繁体   English   中英

如何使mod_rewrite从子域重定向到querystring?

[英]how to make mod_rewrite to redirect from subdomains to querystring?

我想使mod重写为以下示例:

从google.com.mydomain.com到mydomain.com/index.php?domain=google.com

我用像

RewriteCond %{HTTP_HOST} !^www [NC]
RewriteCond %{QUERY_STRING} !domain=
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain.com$ [NC]
RewriteRule ^(.*)$ /index.php?domain=%1 [L,QSA]

但这会将google.mydomain.com重定向到mydomain.com/index.php?domain=google

我希望规则重定向google.com而不是google

谢谢

这是由于不正确的正则表达式。 尝试以下规则:

RewriteCond %{HTTP_HOST} !^www [NC]
RewriteCond %{QUERY_STRING} !domain=
RewriteCond %{HTTP_HOST} ^(.+?)\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ /index.php?domain=%1 [L,QSA]

在您的规则中,您使用的是[^\\.]+ ,直到发现一个点为止,它一直匹配,因此它匹配google而不是google.com

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM