使用 htaccess 从重定向 URL 中删除查询字符串

发布于 2024-12-28 04:26:21 字数 454 浏览 1 评论 0原文

我正在使用以下代码将流量重定向到特定页面(该流量是通过 google 从一个曾经使用我的服务器 IP 的旧网站来的)

RewriteRule ^viewtopic.php?/?$ http://www.myurl.org.uk/ [L,R=301]

据我了解,这个 ^viewtopic.php?/?$< /code> 应该删除查询字符串,但它不起作用。任何帮助表示赞赏。

URL 输出示例

http://www.myurl.org.uk/viewtopic.php?f=3&t=44207&start=2265

重定向时的

http://www.myurl.org.uk/?f=3&t=44207&start=2265

I'm using the following code to redirect traffic to a spesific page (this traffic is coming via google from an old site which used to use my servers ip)

RewriteRule ^viewtopic.php?/?$ http://www.myurl.org.uk/ [L,R=301]

As I understand it this ^viewtopic.php?/?$ should strip away the query string but it isn't working. Any help appreciated.

Example URL

http://www.myurl.org.uk/viewtopic.php?f=3&t=44207&start=2265

Output when redirected

http://www.myurl.org.uk/?f=3&t=44207&start=2265

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热血少△年 2025-01-04 04:26:21

您已经接近答案了...您的 ? 位于错误的一侧。将其放在重定向端以去除查询字符串:

RewriteRule ^viewtopic.php http://www.myurl.org.uk/? [L,R=301]

在 301 重定向中,mod_rewrite 通常会附加完整的查询字符串。但是,在重写的 URL 末尾放置一个 ? ,而没有相应的 [QSA] (“查询字符串附加”)标志,将指示它使用您提供的空白查询字符串。

You were close to the answer... You have the ? on the wrong side. Put it on the redirect side to strip off the query string:

RewriteRule ^viewtopic.php http://www.myurl.org.uk/? [L,R=301]

In a 301 redirect, mod_rewrite will normally append the full query string. But placing a ? at the end of your rewritten URL without a corresponding [QSA] ("querystring append") flag will instruct it instead to use the blank query string you supplied.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文