URL redirect for user profile in .htaccess
Can you please tell me how I can redirect the url
like www.santaraj.com/steve
to a new my file profile.php
?
Actually I want to display the user profile by prof开发者_运维问答ile.php
but the url will remain as domain name/username
(www.santaraj.com/steve
). A good example is www.twiiter.com/kk
.
Put the following rule in .htaccess in your document root:
RewriteRule ^([a-z0-9]+)$ /profile.php?user=$1 [L]
(assumes a 'RewriteEngine on' in the same file)
When a user goes to www.santaraj.com/steve, your profile.php script will be run, with a query string of user=steve.
Note how the regular expression in the rule assumes that user names are composed of numbers and lower case letters. You can change that to whatever makes sense for you, of course.
精彩评论