问题
I have a problem with rewrite condition and rule in Apache2. I want to have dynamic subdomains and dynamic folders, which will rewrite to php script. For example:
sub1.example.com/folder1 => do.php?a=sub1&b=folder1
sub2.example.com/folder2 => do.php?a=sub1&b=folder2
It will looks like every subdomain has own folders. But some subdomain (admin etc) will not be rewrited.
I know how to rewrite subdomain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(^.*)\.example.com/ [NC]
RewriteRule ^(.*)$ do.php?a=%1 [L,P]
but I don't know, how to do dynamic folders in subdomains.
Thanks a lot
回答1:
Maybe this example can help you:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]+)\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/?do\.php$
RewriteRule .? do.php?url=%1&path=%{REQUEST_URI} [L,QSA]
来源:https://stackoverflow.com/questions/14111014/apache-rewrite-dynamic-subdomains-and-url-parameters