tags:

views:

31

answers:

1

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 profile.php but the url will remain as domain name/username (www.santaraj.com/steve). A good example is www.twiiter.com/kk.

+1  A: 

Hi James

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.

mwittrock
Be carefully to not rewrite your images, styles, etc. folders too!
alopix
Indeed. Always test your rewrite rules thoroughly and keep in mind that the order, in which they occur in .htaccess, is significant.
mwittrock
Thanks a lot,ya..great it's working fine?RewriteRule ^([a-z0-9]+)$ /profile.php?user=$1 [L]But what to do with my page "www.santaraj.com/logout" page that also redirecting. how i put the condition for my some pages.
JAMES
If you're rewriting /logout as well (to, say, /logout.php), just make sure that the logout rule occurs before the user rule in .htaccess. You might consider going for /users/X rather than /X, though. Then you wouldn't have to deal with the exceptions.
mwittrock
Thanks a lot again for helping me...
JAMES
No problem. Would you do me a favour and accept the answer?
mwittrock