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
We can do that using .htaccess for translate som3thin9.com/username = som3thin9.com/member.php?id=username
Options FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/?$ member.php?id=$1& [L,NC]
Hi Why have you hard coded the member ID 1? can we not have it hardcoded and it will fetch IDs based on the querystring? Also, what does [L,NC] mean?
If you look correctly, it says $1. This is a reference to the rewriterule before it: ^([^/]+)/? - So $1 contains the member name. NC makes this case insensitive. (No Case) L makes it the last rule if the regex is matched.
if you dont understand why you talking about it? have you at least tried? id=$1 it's a variable which it's not just set to 1 lol
Question: For multiple pages, do I have to write the code as: Options FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/?$ member.php?id=$1& [L,NC] RewriteRule ^([^/]+)/?$ comments.php?id=$1& [L,NC] RewriteRule ^([^/]+)/?$ question.php?id=$1& [L,NC] Code (markup): Pls confirm?
That wont work u hve to make ur site like this som3thin9.com/username som3thin9.com/comments/username som3thin9.com/questions/username try this Options FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/?$ member.php?id=$1& [L,NC] RewriteRule ^([^/]+)/comments/?$ comments.php?id=$1& [L,NC] RewriteRule ^([^/]+)/questions/?$ question.php?id=$1& [L,NC] Code (markup):
You mean I have to create folders to make it work? pls tell me why cannot i use this code? RewriteRule ^([^/]+)/?$ question.php?id=$1& [L,NC] Code (markup):
u dont have to create a folder if u use that .htaccess then ur links will be accesable that way u cannot use that code because for example if i access yoursite.com/43 then it will actually be member.php?id=43 the script wont know what ur actually wanting the question part and not the member part
Oh gotcha! So, how can the following be translated/coded by .htaccess site.com/comments.php?id=10&username=cancer10 Code (markup):
RewriteRule (.*)/(.*)/$ /comments.php?id=$2&username=$1 som3thin9.com/cancer10/10 that will make the link in that format
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] Code (markup):