I was wondering if I’m supposed to use .htaccess to change a get variable to a value from the database (username).
so if there is
http://www.url.com/user.php?u=1
how do you conver it to
http://www.url.com/andrewliu
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to change your
user.phpto take a username instead of a userid. Then you can use something like:This passes the username through the
uquery string parameter, essentially:/user.php?u=andrewliuOtherwise there’s no way htaccess and mod_rewrite can know what the mapping is between user_id and username. Alternatively, you can write a database script and use RewriteMap to create a mapping for you:
and in your htaccess:
The last option, if you’ve only got, say, 5 users (or some small amount), you can make explicit rewrites: