【问题标题】:RewriteCond %{HTTP_HOST} not respondingRewriteCond %{HTTP_HOST} 没有响应
【发布时间】:2014-07-10 08:15:33
【问题描述】:

我想根据子域名重写 url。但是当转到 http://test2.domain.com/test/ 时,它转到 http://test1.domain.com/test/ 。当我测试时,我发现当我删除第一条 RewriteRule 行(test1.domain.com 部分)(RewriteRule ^test/&(.*)$ index.php?menuID=1&$1 [L])时,它正在工作.出了什么问题?

###start_test1.domain.com###
RewriteCond %{HTTP_HOST} ^(test1.)?domain.com [NC]
RewriteCond %{REQUEST_URI} ^/
RewriteRule ^test/&(.*)$ index.php?menuID=1&$1 [L]
RewriteRule ^test/ index.php?menuID=1[L]
###end_test1.domain.com###


###start_test2.domain.com###
RewriteCond %{HTTP_HOST} ^(test2.)?domain.com [NC]
RewriteCond %{REQUEST_URI} ^/
RewriteRule ^test/&(.*)$ index.php?menuID=2&$1 [L]
RewriteRule ^test/ index.php?menuID=2[L]
###end_test2.domain.com###

【问题讨论】:

    标签: php apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    RewriteCond 仅适用于 vey next RewriteRule。此外,您的正则表达式 ^(test2.)?domain.com 看起来不正确。

    有这样的规则:

    RewriteEngine On
    
    ###start_test1.domain.com###
    RewriteCond %{HTTP_HOST} ^test1\.domain\.com$ [NC]
    RewriteRule ^test/&(.*)$ index.php?menuID=1&$1 [L,B]
    
    RewriteCond %{HTTP_HOST} ^test1\.domain\.com$ [NC]
    RewriteRule ^test/ index.php?menuID=1[L]
    ###end_test1.domain.com###
    
    ###start_test2.domain.com###
    RewriteCond %{HTTP_HOST} ^test2\.domain\.com$ [NC]
    RewriteRule ^test/&(.*)$ index.php?menuID=2&$1 [L,B]
    
    RewriteCond %{HTTP_HOST} ^test2\.domain\.com$ [NC]
    RewriteRule ^test/ index.php?menuID=2[L]
    ###end_test2.domain.com###
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-15
      • 2014-09-16
      • 1970-01-01
      • 2010-12-15
      • 1970-01-01
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多