redirect a single URL to another - removing the query string

随声附和 提交于 2019-12-12 17:57:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!