子站点的页面htaccess的重写规则 [英] htaccess Rewrite Rule for subdomain to page
问题描述
目前我居住在一个页面:
Currently I have a page residing at:
http://www.example.com/site/page
在我的htaccess我当前的规则:
In my htaccess I have the current rule:
RewriteRule ^site/(.*)$ retailer.php?linklabel=$1 [QSA]
什么规则模样有网址,该网页成为它自己的子域名:
What would the rule look like to have the URL for that page become it's own subdomain:
http://page.example.com
感谢您的帮助!
Thanks for any help!!
到目前为止,我已经尝试了以下规则,没有工作:
So far I have tried the following rule which hasn't worked:
RewriteRule http://(.*)$.example.com retailer.php?linklabel=$1 [QSA]
也许我需要做的东西在的cPanel首先就一个通配符子域名?我也不太清楚......
Maybe I need to do something in cpanel first regarding a wildcard subdomain? I'm not too sure...
推荐答案
尝试:
RewriteCond %{HTTP_HOST} !^www.[NC]
RewriteCond %{HTTP_HOST} ^(.+?)\.example.com$ [NC]
RewriteRule ^$ retailer.php?linklabel=%1 [L,QSA]
您不能针对一个重写规则
,所以你需要做的是对%{HTTP_HOST} 主机匹配code> VAR在
的RewriteCond
,然后使用 %1
反向引用拿到那场比赛。
You can't match against the host in a RewriteRule
, so you'll need to do it against the %{HTTP_HOST}
var in a RewriteCond
, then use the %1
backreference to get that match.
这将只针对目前的URI的那正是 /
匹配。所以它不会对 http://page.example.com/something
匹配,除非你从改变常规EX preSS的^ $
到 ^东西$
。
This will currently only match against URI's that are exactly /
. So it won't match against http://page.example.com/something
unless you change the regular express at from ^$
to ^something$
.
这篇关于子站点的页面htaccess的重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!