Mobile app version of vmapp.org
Login or Join
Tiffany637

: How do I make SEO friendly URLs? 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

@Tiffany637

Posted in: #Htaccess #ModRewrite #Php

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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Tiffany637

2 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

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

10% popularity Vote Up Vote Down


 

@Shakeerah822

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=
RewriteRule profile/(.*) profile.php?username=


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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme