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
到
/new-website-page/
我有多个查询要做,这里有几个例子:
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
我也试过这个:
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 中的任何现有查询字符串.