Caro_deb
Caro_deb

Reputation: 279

htaccess rewrite mod: vanity url

I've looked on SO but wasn't able to find the answer to my issue.

How can I go from :

 localhost/profile.php?id=22

to:

 localhost/charlie 

Charlie would be the username (not the first name) here.

I also want to make sure that whether a user types in

 localhost/profile.php?id=22 

or

 localhost/charlie 

they get redirected to the appropriate profile they're looking for.

Thanks !

Upvotes: 0

Views: 418

Answers (1)

anubhava
anubhava

Reputation: 785481

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+profile\.php\?id=22\s [NC]
RewriteRule ^ /charlie? [R=302,L]

RewriteRule ^charlie/?$ /profile.php?id=22 [NC,L,QSA]

Upvotes: 1

Related Questions