Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

My url is: website.com/profile/?id=24

I want it to be: website.com/profile/kevinlee

The ?id=24 will be replaced with the username of the id=24 in the database

How do I convert it to that?

share|improve this question

migrated from stackoverflow.com Jan 1 '12 at 3:47

This question came from our site for professional and enthusiast programmers.

    
Maybe something like: 9lessons.info/2011/04/seo-friendly-urls-with-php.html? –  M.Babcock Jan 1 '12 at 3:41
1  
Is this about some arbitrary database, or an existing known application, eg. WordPress? If the back end is custom, it seems this should go back to SO for an explanation of the coding for setting up a controller to handle this etc., no? –  Su' Jan 1 '12 at 11:43
    
@M.Babcock, will this slow down the system? Because querying using integer is faster rather than querying by string –  Kevin Lee Jan 1 '12 at 12:28
add comment

2 Answers 2

up vote 4 down vote accepted

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):

Options +FollowSymLinks
RewriteEngine on
RewriteRule profile/(.*)/ profile.php?username=$1
RewriteRule profile/(.*) profile.php?username=$1

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.

share|improve this answer
add comment

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 :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.