How to stop htaccess rewrite rule carrying over qu

2019-08-05 23:46发布

问题:

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]