htaccess 使用查询字符串重定向失败

发布于 2024-12-29 19:04:29 字数 569 浏览 4 评论 0原文

尝试将带有查询字符串的 URL 重定向到子域,但无法使其工作。

目标是使 www.example.com/services/json?method=views.get 成为 old.example.com/services/json?method=views.get

我在 .htaccess 文件中:

RedirectMatch 301 ^www\.example\.com/services/json$ http://old.example.com/services/json$1

在 Chrome 中,它只停留在 www 域。

在 Firefox 中,它会失败一次,并显示“Firefox 已检测到服务器正在以永远不会完成的方式重定向对此地址的请求。”但是如果我点击“重试”,它会转到子域很好。

这令人愤怒,我们将不胜感激任何帮助。我尝试了几种不同的模式。

谢谢!

此外,查询字符串中还有双引号。是否可以保留它们而不将其编码为 %2522

Trying to redirect a URL with a query string to a subdomain, and can't get it to work.

The goal is to make www.example.com/services/json?method=views.get become old.example.com/services/json?method=views.get

I have in the .htaccess file:

RedirectMatch 301 ^www\.example\.com/services/json$ http://old.example.com/services/json$1

In Chrome, it just stays at the www domain.

In Firefox, it fails once, saying "Firefox has detected that the server is redirecting the request for this address in a way that will never complete." But if I hit Try Again, it goes to the subdomain just fine.

This is infuriating, and any help is appreciated. I've tried several different patterns.

Thanks!

Also, there are double quotes in the query string. Is it possible to keep them without them becoming encoded to %2522?

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

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

发布评论

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

评论(2

带刺的爱情 2025-01-05 19:04:29

试试这个:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://old.example.com/$1 [R=301,L]

Try this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://old.example.com/$1 [R=301,L]
林空鹿饮溪 2025-01-05 19:04:29

我明白了这一点。这是我让它工作的方法:

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^services/json(.*)$ http://old.example.com/services/json$1 [NE,L,R=301]

现在一切都很完美。

规则末尾的 NE 标记根据需要在查询字符串中保留双引号,并且不对它们进行编码。

I figured this out. Here is what I put to get it working:

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^services/json(.*)$ http://old.example.com/services/json$1 [NE,L,R=301]

Everything works perfectly now.

The NE tag at the end of the rule keeps the double quotes in the query string, as needed, and doesn't encode them.

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