Log In

Email:
Password:
Keep me logged in

Forgot Password

Email:




CategoriesCSS (4)
jQuery (56)
PHP (26)
.htaccess (2)
Sponsored Links



Rewrite Username URL
Thursday, December 1, 2011 by William Thomas



Info:
.htaccess, the file to edit. This should already be in your site root
(obtainable in Control Panel), but hidden.
If not, make a file named ".htaccess", edit and then upload to site root.
Use the filename of the profile page, for example profile.php, to reference in the .htaccess file.

Code:
RewriteEngine On
RewriteRule ^([A-Za-z0-9]+)$ profile.php?user=$1
RewriteRule ^([A-Za-z0-9]+)/$ profile.php?user=$1

#Before it was just "http://example.com/profile.php?user=wcet2011".
#Rewrites as "http://example.com/wcet2011", for example.
#'$1' refers to the 1st group in the pattern, which is and must be in parenthesis.
#[A-Za-z0-9] is the alphanumeric pattern, this can vary depend on your username character limits.
#'+' means there must be at least 1 character in the pattern, otherwise it will redirect to your home page.
Views: 115 Likes: 0 Dislikes: 0