本文介绍了Apache-重写动态子域和URL参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对Apache2中的重写条件和规则有疑问.我想要动态子域和动态文件夹,它们将重写为php脚本.例如:
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.
我知道如何重写子域:
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.
非常感谢
推荐答案
也许此示例可以为您提供帮助:
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]
这篇关于Apache-重写动态子域和URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!