【问题标题】:Apache mod_rewrite: explain me %{HTTP_HOST} especially when using addon domainsApache mod_rewrite:向我解释 %{HTTP_HOST} 尤其是在使用插件域时
【发布时间】:2011-03-16 00:42:54
【问题描述】:

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} 是否计算为服务器上当前请求的 url 的域???

所以如果要求:

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"???

【问题讨论】:

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


    【解决方案1】:

    %{HTTP_*} 计算为 HTTP 标头,其名称在显示的前缀后给出。在 HTTP 1.1 中,被访问的主机在 Host 标头中给出,所以是的。

    【讨论】:

    • 这意味着,客户端发送变量的内容。你不能相信来自客户的任何东西。并且您不应该在重写规则中使用不受信任的数据。
    【解决方案2】:

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

    main-domain.com
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-03
      • 2011-03-15
      • 2011-03-13
      • 2011-04-23
      相关资源
      最近更新 更多