htaccess的301重定向 - 删除查询字符串(QSA)

问题描述:

我一直挣扎着一些htaccess的重定向。我只是花了一些时间阅读和搜索上的堆栈并不能得到与我的情况下工作的anwser。

I've been struggling with some htaccess redirects. I just spent some time reading and searching on stack and couldn't get an anwser that works with my scenario.

我在使301重定向为旧客户的网站以一个新的过程。旧的网页有,我想从URL删除参数查询。

I'm in the process of making the 301 redirect for an old client website to a new one. The old pages has parameters query which I want to remove from the url.

/menu.php?idCategorie=29&idDetail=172

/新网站页面/

我有多个疑问的事情,这里有一对夫妇的例子:

I have multiple queries to do, here's a couple example:

/menu.php?idCategorie=29&idDetail=172
/menu.php?idCategorie=29&idDetail=182
/menu.php?idCategorie=29&idDetail=184
/menu.php?idCategorie=29&idDetail=256

所有链接到不同的新的页面。

Which all link to different new pages.

下面是我的尝试:

RewriteCond %{QUERY_STRING} idDetail=172
RewriteRule ^menu.php(.*) /new-page/? [R=301,L]

我得到正确的重定向,但是URL保留查询字符串:

I get redirected correctly, but the URL keeps the query string:

http://website.com/new-page/?idCategorie=29&idDetail=172

我也试过这样的:

I also tried this:

RewriteRule ^menu.php?idCategorie=29&idDetail=172$ http://website.com/new-page/? [L,R=301]

和这样的:

RewriteCond %{QUERY_STRING} idDetail=172(.*)$
RewriteRule ^menu.php /new-page-name?$1 [L,R=301]

和它不工作(还有在最后的查询字符串)

And it didn't work (Still have the query string at the end)

谢谢!

您可以使用此规则:

RewriteRule ^menu\.php$ /new-page-name? [L,R=301]

记到底哪个是用于剥离任何现有的查询字符串在原始的URI。