Reputation: 80
i am totally newbie for .htaccess or apache. Don't know how it works.
my url is like
http://localhost/category.php?category=something
i wanna get the variable value as something in category.php but wanna show the url as
http://localhost/something
how can i do this please help.
Thank you in advance
Upvotes: 0
Views: 1827
Reputation: 19528
First rule will redirect the ugly URL to the pretty URL, second rule will internally redirect the pretty URL back while not changing what the user see on the browser URL:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# Redirect /category.php?category=something to /something
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+category\.php\?category=([^&\s]+) [NC]
RewriteRule ^ /%1? [R=302,L]
# Internally forward /something to /category.php?category=something
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/?$ /category.php?category=$1 [QSA,NC,L]
Once you confirm its working as expected change R=302
to R=301
.
Upvotes: 1