Apache mod_rewrite:解释我%{HTTP_HOST},尤其是在使用插件域时

时间:2010-07-14 18:46:18

标签: apache mod-rewrite dns add-on http-host

Apache mod_rewrite:解释我%{HTTP_HOST},特别是在使用插件域时

具有插件域的Apache服务器上的情境(目录树):

main-domain.com/ 
| 
|_ .htaccess (just an empty file, no rule in here) 
|_ index.html (shown when accessing http://main-domain.com)
| 
|_ addon-domain-1.com/ 
|  | 
|  |_ .htaccess 
|  |_ index.html (shown when accessing http://addon-domain-1.com or http://main-domain.com/addon-domain-1.com/)
| 
|_ addon-domain-2.com/ 
   | 
   |_ .htaccess 
   |_ index.html (shown when accessing http://addon-domain-2.com or http://main-domain.com/addon-domain-2.com/)

我们在“addon-domain-1.com/.htaccess”文件中说我有一些使用%{HTTP_HOST}的规则,如:

RewriteCond %{HTTP_HOST} ^something$

%{HTTP_HOST}是否评估服务器上当前请求的网址?

所以如果要求:

http://addon-domain-1.com/

%{HTTP_HOST} will be "addon-domain-1.com"?

http://addon-domain-1.com(没有最终斜杠)

%{HTTP_HOST} will still be "addon-domain-1.com"?

http://www.addon-domain-1.com

%{HTTP_HOST} will still be "www.addon-domain-1.com"?

当要求:

http://main-domain.com/addon-domain-1.com

%{HTTP_HOST} will be "main-domain.com"???
or "main-domain.com/addon-domain-1.com"???

2 个答案:

答案 0 :(得分:5)

%{HTTP_*}使用在显示前缀后给出的名称来评估HTTP标头。在HTTP 1.1中,被访问的主机在Host标头中给出,所以是的。

答案 1 :(得分:4)

你几乎猜对了他们!最后一个是;

main-domain.com