htaccess RewriteRule 意外重定向 www

发布于 2024-09-25 18:36:30 字数 611 浏览 0 评论 0原文

在我的 htaccess 中,我有一个规则 -

我有这个规则

RewriteRule ^mk$ http://mysite.com/mypage.php [r=301,nc]

,稍后:

RewriteCond %{HTTP_HOST} !^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [QSA,L,R=301]

这适用于 http://mysite.com/mk
- 它重定向到: http://mysite.com/mypage.php 如我所愿。

...但是当我去 http://www.mysite.com/mk 它重定向到 http://mysite.com/http://mysite.com/ mypage.php

这两条规则不兼容吗?谁能告诉我发生了什么事以及该怎么办?

谢谢

In my htaccess I have a rule -

I have this rule

RewriteRule ^mk$ http://mysite.com/mypage.php [r=301,nc]

and later on :

RewriteCond %{HTTP_HOST} !^mysite\.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [QSA,L,R=301]

This works fine for
http://mysite.com/mk
- it redirects to:
http://mysite.com/mypage.php
as I wanted.

...but when I go to
http://www.mysite.com/mk
it redirects to http://mysite.com/http://mysite.com/mypage.php

Are these 2 rules incompatable? Can anyone tell me what's happening and what to do?

Thanks

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

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

发布评论

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

评论(1

半葬歌 2024-10-02 18:36:30

它们是兼​​容的,但就你而言,我认为顺序很重要。我会将 host 重定向移至 mk 重定向之上,然后重试。

另一件事是将 L 标志(Last)添加到 mk 规则中。这应该立即触发重定向。

我不确定您是否还有其他要首先运行的规则。因此,如果这对您很重要,请查看订单的作用。本质上,这些规则是配对和双重重写http://www.mysite.com/mk

They are compatible, but in your case I think order matters. I would move the host redirect above the mk redirect and try again.

Another thing would be to add the L flag (Last) to the mk rule. This should trigger the redirect immediately.

I am not sure if you have any other rules that you want to run first. So see what the order does if that matters to you. Essentially these rules are pairing up and double rewriting http://www.mysite.com/mk

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