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

Mar*_*aio 10 apache dns mod-rewrite add-on http-host

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

具有插件域的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/)
Run Code Online (Sandbox Code Playgroud)

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

RewriteCond %{HTTP_HOST} ^something$
Run Code Online (Sandbox Code Playgroud)

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

所以如果要求:

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

%{HTTP_HOST} will be "addon-domain-1.com"?
Run Code Online (Sandbox Code Playgroud)

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

%{HTTP_HOST} will still be "addon-domain-1.com"?
Run Code Online (Sandbox Code Playgroud)

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

%{HTTP_HOST} will still be "www.addon-domain-1.com"?
Run Code Online (Sandbox Code Playgroud)

当要求:

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

%{HTTP_HOST} will be "main-domain.com"???
or "main-domain.com/addon-domain-1.com"???
Run Code Online (Sandbox Code Playgroud)

Ign*_*ams 6

%{HTTP_*}在显示前缀后给出名称的HTTP头.在HTTP 1.1中,正在访问的主机在Host标头中给出,所以是的.


The*_*dic 5

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

main-domain.com
Run Code Online (Sandbox Code Playgroud)