Reputation: 35
I want to redirect this:
example.com/product-name-p12.html
(it's product_page.php?id=12 rewrited)
to:
www.example.com/product-name-p12.html
If I'm using this Rewrite rule:
RewriteRule ^(.*)-p(.*).html$ product_page.php?id=$2&%{QUERY_STRING}
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
it's redirecting to www.example.com/product_page.php?id=12, not to the html version.
Thanks a lot,
Upvotes: 2
Views: 78
Reputation: 785551
Reverse the ordering of your rule and use QSA
flag. QSA
(Query String Append) flag preserves existing query parameters while adding a new one.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NE]
RewriteRule ^(.*)-p(.*)\.html$ product_page.php?id=$2 [L,QSA]
Upvotes: 1