htaccess的自动检测域名 [英] htaccess automatically detect domain name
问题描述
我做了自动创建子域的脚本。
I made script that automatically create subdomain.
htaccess的做工精细, 但问题是,我需要在新站点安装手动更改域名的。
the htaccess working fine, but the problem is, i need to manually change domain name when install on new domain.
我要自动检测htaccess的域名,这可能吗?
I want to automatically detect domain name in htaccess, is that possible?
因此,在另一个服务器或新的域添加时的无需更改域根htaccess的再的。
so when adding in another server or new domain, no need to change the domain root htaccess again.
域根htaccess是:
domain root htaccess is:
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9][-a-z0-9]+)\.mydomain\.com(:80)?$ [NC]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com
我试图自动改变从获得%{HTTP_HOST}
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9][-a-z0-9]+)\.%{HTTP_HOST}(:80)?$ [NC]
RewriteCond %{HTTP_HOST} !^www\.%{HTTP_HOST}
问题是%{HTTP_HOST}
,
如何获得/匹配当前域在当前的URL与htaccess的?
the problem is on %{HTTP_HOST}
,
how to get/match current domain in current url with htaccess?
也许需要得到的域名作为变量
感谢您
推荐答案
我相信这的RewriteCond
应该为你工作:
I believe this RewriteCond
should work for you:
RewriteCond %{HTTP_HOST} ^(?:www\.)?((?!www\.)[^.]+)\.([^.]+\.[^.]+)$ [NC]
因此,对于前;与像 http://www.sub.domain.com
的URL会捕捉子
在%1
变量和 domain.com
在%2
变量。
So for ex; with a URL like http://www.sub.domain.com
it will capture sub
in %1
variable and domain.com
in %2
variable.
这篇关于htaccess的自动检测域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!