简体   繁体   中英

RewriteCond %{HTTP_HOST} not responding

I want to rewrite urls based on subdomain names. But when go to http://test2.domain.com/test/ it goes to http://test1.domain.com/test/ . When I was testing I found that when I removed the first RewriteRule line (of the test1.domain.com part) (RewriteRule ^test/&(.*)$ index.php?menuID=1&$1 [L]) it was working. What is going wrong?

###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###

RewriteCond is only applicable to vey next RewriteRule . Also your regex ^(test2.)?domain.com is not looking correct.

Have your rules like this:

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###

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM