1

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?

3
  • Maybe something like: 9lessons.info/2011/04/seo-friendly-urls-with-php.html?
    – M.Babcock
    Commented Jan 1, 2012 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'
    Commented Jan 1, 2012 at 11:43
  • @M.Babcock, will this slow down the system? Because querying using integer is faster rather than querying by string
    – Kevin Lee
    Commented Jan 1, 2012 at 12:28

2 Answers 2

4

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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