Apache - Rewrite dynamic subdomains and URL parameters

蓝咒 提交于 2020-01-06 18:06:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!