问题检测空REQUEST_URI与Apache的mod_rewrite [英] Problem detecting empty REQUEST_URI with Apache mod_rewrite

查看:119
本文介绍了问题检测空REQUEST_URI与Apache的mod_rewrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行的Apache重定向难熬这样的规则:

I am running Apache witha redirect rule like this:

RewriteCond %{HTTP_HOST} ^1st-domain\.com
RewriteRule ^(.*)$ http://2nd-domain.com$1 [R=permanent,L]

这成功重定向 http://1st-domain.com 来的 http://2nd-domain.com
然而,当REQUEST_URI是空的,我想重定向到第三个域。

This successfully redirects http://1st-domain.com to http://2nd-domain.com However, when the REQUEST_URI is empty, I want to redirect to a third domain.

RewriteCond %{HTTP_HOST} ^1st-domain\.com$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ http://3rd-domain.com$1 [R=permanent,L]

但是,这并不工作,而不是重定向到2nd-domain.com

But this does not work and instead redirects to 2nd-domain.com

我的规则是有顺序是这样的:

My rules are ordered like this:

RewriteCond %{HTTP_HOST} ^1st-domain\.com$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ http://3rd-domain.com$1 [R=permanent,L]

RewriteCond %{HTTP_HOST} ^1st-domain\.com
RewriteRule ^(.*)$ http://2nd-domain.com$1 [R=permanent,L]

有什么建议?谢谢你在前进。

Any suggestions? Thank you in advance.

更新


  1. 空REQUEST_URI:HTTP:/1st-domain.com

  2. 非空REQUEST_URI: http://1st-domain.com/something

  1. Empty REQUEST_URI: http:/1st-domain.com
  2. Non-empty REQUEST_URI: http://1st-domain.com/something

第一条规则应该直接空REQUEST_URI到3rd-domain.com,第二条规则应该引导非空REQUEST_URI到2nd-domain.com

The first rule should direct an empty request_uri to 3rd-domain.com, the second rule should direct the non-empty request_uri to 2nd-domain.com

有用的珍闻
您可以在mod_rewrite的调试打开这个片段:

USEFUL TIDBIT You can turn on mod_rewrite debug with this snippet:

<IfModule mod_rewrite.c>
RewriteLog "/home/domain.com/logs/rewrite.log"
RewriteLogLevel 3
</IfModule>

我还不知道非常有用的调试选项。

Very useful debug option I hadn't known.

推荐答案

这应该工作:

RewriteCond %{HTTP_HOST} ^1st-domain\.com
RewriteRule ^$ http://3rd-domain.com [R=permanent,L]

RewriteCond %{HTTP_HOST} ^1st-domain\.com
RewriteRule ^(.+)$ http://2nd-domain.com/$1 [R=permanent,L]

希望它帮助!

请注意:REQUEST_URI之间的httpd.conf和的.htaccess略有不同,它在httpd.conf一个额外的反斜杠开始。这意味着,在httpd.conf中的第一个重写规则应该是 ^ \\ / $ ,而不仅仅是 ^ $

Note: REQUEST_URI is slightly different between httpd.conf and .htaccess, it starts with an extra backslash in httpd.conf. This means that in httpd.conf the first rewrite rule should be ^\/$, not just ^$.

这篇关于问题检测空REQUEST_URI与Apache的mod_rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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