如何使mod_rewrite的从子域名重定向到查询字符串? [英] how to make mod_rewrite to redirect from subdomains to querystring?
本文介绍了如何使mod_rewrite的从子域名重定向到查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想让mod-rewrite如下面的例子:
I want to make mod rewrite as the following example :
从google.com.mydomain.com到mydomain.com/index.php?domain=google.com
from google.com.mydomain.com to 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~~V
but this redirect google.mydomain.com to mydomain.com/index.php?domain=google
我要统治重定向google.com不是谷歌
I want rule to redirect google.com not google
感谢
推荐答案
这是由于不正确的正则表达式。试试这个规则:
It is due to the incorrect regex. Try this rule:
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteCond %{QUERY_STRING} !domain=
RewriteCond %{HTTP_HOST} ^(.+?)\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ /index.php?domain=%1 [L,QSA]
在您的规则你使用 [^ \\。] +
这匹配,直到点被发现,因此被匹配谷歌
,而不是 google.com
。
In your rule you're using [^\.]+
which matched until a dot is found therefore it is matching google
instead of google.com
.
这篇关于如何使mod_rewrite的从子域名重定向到查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文