View Full Version : website.com/username
cancer10
08-27-2009, 06:23 AM
Hi
I was wondering how do they do that website.com/any-username thing?
Just like when you signup at twitter, you get u a vanity url like twitter.com/cancer10
Does anyone know?
Pls if someone can explain :)
Thanks
Fou-Lu
08-27-2009, 08:23 AM
Mod_rewrite
Moving from PHP forum to Apache configuration forum.
I assumed you're using Apache as well, I don't know of IIS has a similar rewrite module or not.
cancer10
08-27-2009, 08:24 AM
I am using Apache, yes
What is the syntax, pls if you can post?
Thanks
Fou-Lu
08-27-2009, 08:54 AM
I lol'd. Thought I put an example in the last:
RewriteEngine ON
RewriteRule ^.*/([^/\.]+)/?$ userPage.php?page=$1 [L]
Doesn't need to be a PHP page, but it should certainly be dynamically creatable.
Look into this link: http://www.workingwith.me.uk/articles/scripting/mod_rewrite
cancer10
09-03-2009, 08:23 AM
Question:
For multiple pages, do I have to write the code as:
RewriteEngine ON
RewriteRule ^.*/([^/\.]+)/?$ userPage.php?page=$1 [L]
RewriteRule ^.*/([^/\.]+)/?$ questions.php?page=$1 [L]
RewriteRule ^.*/([^/\.]+)/?$ comments.php?page=$1 [L]
cancer10
02-10-2010, 08:54 AM
I was waiting for an answer :(
pls if someone can answer to my saecond last post
Thanks
Fou-Lu
02-10-2010, 02:29 PM
No, the above would always match the first pattern and rewrite it to the userPage.php style.
To do a more specific target, you'll need to write a more specific condition. Say you're link is /Comments/765, so the comment is the 765th comment. That would be like so:
RewriteRule ^.*/Comments/(\d+)/?$ comments.php?page=$1 [L]
You can setup rule chaining, but you'll need to find someone much more knowledgeable with rewrite than I.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.