htaccess 301 重定向 - 删除查询字符串 (QSA) [英] htaccess 301 redirect - Remove query string (QSA)

查看:28
本文介绍了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 中的任何现有查询字符串.

这篇关于htaccess 301 重定向 - 删除查询字符串 (QSA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆