My url is:
I want it to be:
?id=24 will be replaced with the username of the
id=24 in the database
How do I convert it to that?
migrated from stackoverflow.com Jan 1 '12 at 3:47
This question came from our site for professional and enthusiast programmers.
If the user names (like kevinlee) are unique on the system, this is pretty straight forward. First, for simplicity, I would move the profile call to a profile.php page, and move it out of the /profile/ directory (I'm assuming it used to just be an index.php page in /profile/?). You don't have to do that, but it just makes the .htaccess work a little cleaner if you do.
Now, for the .htaccess, use this (sort of rough, and untested, but should work fine):
That'll take whatever is after profile/ and add it a call to profile.php?username=, so if you hit profile/kevinlee in your browser, it'll actually be hitting profile.php?username=kevinlee on your server.
I give my two cents here.
For me, as long as the url does not have ? & then it's good enough for search engines. If I can have some keywords in it, separate with - or _, then perfect
for your questions: website.com/profile/?id=24 => website.com/profile/kevinlee
cannot be done by simply URL rewrite, it has to be code somewhere to get "kevinlee" as id 24
BUT, if you just make it website.com/profile/?id=24 => website.com/profile/24 then can be done by URL rewrite just as another Eric says :)