了解使用重定向HTTP_HOST [英] Understanding redirection using HTTP_HOST
问题描述
我目前正在经历上重定向的教程,并已变得稍微困惑。
以下是应该为当前站点的所有请求重定向到一个新的领域。
I am currently going through a tutorial on redirects and have become slightly confused. The following is supposed to redirect all requests to the current domain to a new domain.
RewriteCond %{HTTP_HOST} old_domain\.com [NC]
RewriteRule ^(.*)$ http://www.new_domain.com/$1 [L,R=301]
不过是什么 HTTP_HOST
的目的是什么?它包含什么?对我来说, HTTP_HOST
包含当前的主机名? ( old_domain.com
),因此我上面的规则的理解是,它是包含旧域名,然后再按旧域的字符串测试? old_domain.com/old_domain.com
However what is the purpose of HTTP_HOST
? What does it contain? To me HTTP_HOST
contains the current hostname? (old_domain.com
) therefore my understanding of the above rule is that it is testing for a string containing the old domain followed by the old domain again? old_domain.com/old_domain.com
应该不会有呢?
RewriteCond %{HTTP_HOST} [NC]
RewriteRule ^(.*)$ http://www.new_domain.com/$1 [L,R=301]
另外一个例子来帮助理解如何将您重定向到 mysite.com
的请求(其次是没有别的,所以基本上到索引页面请求) mysite2.com
使用 HTTP_HOST
?
As another example to aid understanding how would you redirect a request to mysite.com
(followed by nothing else, so essentially a request to the index page) to mysite2.com
using HTTP_HOST
?
感谢。
推荐答案
该条件检查提供的主机%{HTTP_HOST}
对旧的。所以,如果一个请求进入与主机old_domain.com服务器那么接下来的规则应该运行。如果主机为别的,甚至www.old_domain.com,那么接下来的规则将被跳过。
The condition is checking the supplied host %{HTTP_HOST}
against the old one. So if a request comes into the server with the host "old_domain.com" then the next rule should be run. If the host is anything else, even www.old_domain.com, then the next rule will be skipped.
如果说一种方式,%{HTTP_HOST}
是用户传递给服务器。这个条件会检查用户再次提供什么你写的规则。
To say it another way, %{HTTP_HOST}
is what the user passes to the server. That condition checks what the user supplied again what you've written rules for.
这篇关于了解使用重定向HTTP_HOST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!