Reputation: 2811
I am trying to rewrite this url: http://www.sample.com/product_guide&product_name=waht&product_type=dog-clipper
to:
http://www.sample.com/waht/dog-clipper
I am using this htaccess code:
RewriteCond %{QUERY_STRING} ^product_guide&product_name=(.*)&product_type=(.*)$
RewriteRule ^$ %1/%2? [R=301, L]
But it doesn't work. Please help me.
Upvotes: 2
Views: 3495
Reputation: 270617
If you want users to access http://www.sample.com/waht/dog-clipper
, you have your rewrites backward. You need to match that URL and rewrite it to the appropriate query string:
RewriteEngine On
# Don't match real existing files so CSS, scripts, images aren't rewritten
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Match the first two groups before / and send them to the query string
RewriteRule ^([^/]+)/([^/]+) product_guide?product_name=$1&product_type=$2 [L]
Upvotes: 3