RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{QUERY_STRING} !^id=.
RewriteRule (.*) /index.php?id=%1 [L]
如果有子域名(test.example.com
),则转到文件夹/service/
,如果没有,则转到文件夹/site/
。
test.example.com/post?id=2 -> public_html/service/post.php?id=1
test.example.com/category?id=3 -> public_html/service/category.php?id=3
example.com/register.php -> public_html/site/register.php
答案 0 :(得分:0)
请尝试以下规则:
RewriteCond %{HTTP_HOST} !=www.example.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteRule !^service/ service/index.php?id=%1 [L]
RewriteCond %{HTTP_HOST} =example.com
RewriteRule !^site/ site%{REQUEST_URL} [L]