问题
I have a single url something like this where 456 is the ID of the category and has been rewritten into a seo friendly url:
http://www.mydomain.com/category/nameofcategory/456.htm
(This is done with this rewrite rule:
RewriteRule ^category/.*/([0-9]+) home/categoryview.php?id=$1 [L,QSA]
I need to keep this intact for all the other categories.)
I'd like to .htaccess redirect my 456 category to a specific product's url:
http://www.mydomain.com/products/nameofproduct/123.htm
If add the following to the .htaccess file
Redirect 301 /category/nameofcategory/456.htm http://www.mydomain.com/products/nameofproduct/123.htm
then the ID is added to the url and returns another product like this.
http://www.mydomain.com/products/nameofproduct/123.htm?456
Is there a way to remove the '?456'
回答1:
Don't mix mod_rewrite
and mod_alias
rules. Have all rules in mod_rewrite
only.
RewriteEngine On
RewriteRule ^category/[^/]+/456.htm /products/nameofproduct/123.htm? [L,R=301,NC]
RewriteRule ^category/[^/]+/([0-9]+) /home/categoryview.php?id=$1 [L,QSA]
来源:https://stackoverflow.com/questions/24078560/redirect-a-single-url-to-another-removing-the-query-string