htaccess通配符子域重写导致循环的子文件夹


htaccess wildcard subdomain rewrite subfolder causing loop

我们使用的是通配符子域*.subdomain.com每个州在/state/目录中都有自己的目录,在该目录中有一个state.html。URL将是domain.com/state/$state/state.html,然后会重写为显示domain.com/state.html?state=$state

所有工作都很好,但现在我们需要从子文件夹转到子域,所以最终结果将是

$state.domain.com-首选但非必需或$state.domain.com/state.html?state=$state

我们目前拥有的内容如下,但我们得到了一个重定向循环。

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www'.domain.com
RewriteCond %{HTTP_HOST} ^(.+).domain.com
RewriteRule ^([^/]*)$ /state/%1 [P,L,QSA]
#Rewrite Rule - Force state and city lookup to use state.html or city.html and use info from url to define which city and state.
RewriteRule ^state/(.*)$ state.html?state=$1 [L]
RewriteRule ^city/(.*)/(.*)$ city.html?city=$1&state=$2 [L]

最终使用了以下有效的

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www'.domain.com
RewriteCond %{HTTP_HOST} ^(.+).domain.com
RewriteRule ^([^/]*)$ /state/%1/state.html?state=$1 [L,QSA]