How to stop htaccess rewrite rule carrying over query string

こ雲淡風輕ζ 提交于 2019-12-11 08:22:51

问题


I am setting up some redirects. I want to redirect the following URL:

/cms/index.php?cat_id=2

to the following URL:

/flash-chromatography

The rule I currently have is as follows:

RewriteCond %{QUERY_STRING} ^cat_id=2$ [NC]
RewriteRule ^cms/index\.php$ /flash-chromatography [L,R=301]

This rule is almost perfect apart from it redirect the URL to the following:

/flash-chromatography?cat_id=2

So you see my problem is it has kept the ?cat_id=2 part when I don't want it to.

How do I stop it keeping this bit?


回答1:


Just add ? at the end of rewritten URL:

RewriteCond %{QUERY_STRING} ^cat_id=2$ [NC]
RewriteRule ^cms/index\.php$ /flash-chromatography? [L,R=301]


来源:https://stackoverflow.com/questions/10122530/how-to-stop-htaccess-rewrite-rule-carrying-over-query-string

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