带有查询字符串 HTaccess 的子域
Subdomain with Query String HTaccess
我有以下 htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.*).domain\.com
RewriteRule ^(.*)$ index-merchant.php?id=%1 [NC,QSA]
它可以捕获 $_GET['id'] 值,但现在我想在
中添加一些东西
我要捕捉
sub.domain.com/anything1/anylength
sub.domain.com/anything1/anything2/anything3
我想捕获 anything1/anything2/anything3 作为 $_GET['query_string'];
查询字符串可以是任何形式的长度,总而言之,如果可能的话,我想将其捕获为通配符 (.*)
如何让我的 .htaccess 能够捕获 $_GET['query_string'] 和 $_GET['id'] 这是我的子域
谢谢!
您不需要使用 %
匹配项,因为这些匹配项仅供在 RewriteCond
中捕获的组使用。需要用美元符号$
代替,记得又从1开始:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.*).domain\.com
RewriteRule ^(.*)$ index-merchant.php?id=%1&q= [NC,QSA,L]
现在,对 sub.domain.com/anything1/anylength
的请求将重写为 /index-merchant.php?id=sub&q=anything1/anylength
。
此外,添加 L
标志(如图所示),以防您决定在此规则下方添加任何其他规则。
我有以下 htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.*).domain\.com
RewriteRule ^(.*)$ index-merchant.php?id=%1 [NC,QSA]
它可以捕获 $_GET['id'] 值,但现在我想在
中添加一些东西我要捕捉
sub.domain.com/anything1/anylength
sub.domain.com/anything1/anything2/anything3
我想捕获 anything1/anything2/anything3 作为 $_GET['query_string']; 查询字符串可以是任何形式的长度,总而言之,如果可能的话,我想将其捕获为通配符 (.*)
如何让我的 .htaccess 能够捕获 $_GET['query_string'] 和 $_GET['id'] 这是我的子域
谢谢!
您不需要使用 %
匹配项,因为这些匹配项仅供在 RewriteCond
中捕获的组使用。需要用美元符号$
代替,记得又从1开始:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.*).domain\.com
RewriteRule ^(.*)$ index-merchant.php?id=%1&q= [NC,QSA,L]
现在,对 sub.domain.com/anything1/anylength
的请求将重写为 /index-merchant.php?id=sub&q=anything1/anylength
。
此外,添加 L
标志(如图所示),以防您决定在此规则下方添加任何其他规则。