I would like to create Vanity URLs for web application built ontop of Playframework.
I have tried to add a parameter for index
method in main page Application
, this will work if i call http://localhost:9000/?vanity_url
and not for http://localhost:9000/vanity_url
.
How would i achieve this? I would like users to create their own urls for the solution has to be dynamic, just like on Facebook
In the route you would put
GET /{<[a-z]+>fanPage}/? Page.showFanPage
With this one you could obtain:
http://localhost:9000/facebook
I also recommend using the
slugify
method provided by play framework, usually you would both check if the slug exists in the database, and look up for slug to grab the data (title of the fanpage/who's the owner of the fan page/how many views/etc etc)In the tables:
Name: fanpage
pageID integer or bigint
title varchar
slug varchar unique
owner integer
content text
In code:
I'm going on examples here on how to create the urls since I don't know what app you are building:
GET /post/slug/? Page.createPage
POST /post/slug/? Page.processPage
(note this is just an example, I don't know what kind of application you are building) I hope this helps, let me know if this is what you meant