Mod rewrite 是否为子文件夹重写表达式?

Mod rewrite 是否为子文件夹重写表达式?,mod-rewrite,Mod Rewrite,我打开了通配符子域,并在我的根目录中进行重写以捕获子域和文件夹: RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !www.mysite.com$ [NC] RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.mysite\.com$ [NC] RewriteRule ^(.*)$ process.php?id=%2 RewriteRule ^([^/.]+)/?$ process.php?id=%

我打开了通配符子域,并在我的根目录中进行重写以捕获子域和文件夹:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www.mysite.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.mysite\.com$ [NC]
RewriteRule ^(.*)$ process.php?id=%2
RewriteRule ^([^/.]+)/?$ process.php?id=%2/$1 [L]
如果没有请求子文件夹,最后第二行应该只带我们去process.php?id=subdomain。最后一行应该是process.php?id=subdomain/subfolder/如果确实有请求的子文件夹(如subdomain.mysite.com/subfolder/)


每种方法都有各自的作用,但它们结合在一起就不起作用了。如果没有指定子文件夹,我只希望它使用第一个,如果有,则使用最后一个。我怀疑它们需要与正则表达式结合,但我不知道如何表达这一点?

交换最后两行的顺序。从第二行到最后一行可能变得贪婪,并匹配两种情况…

更改顺序没有任何效果。你还能想到别的吗?