2008-10-23 65 views
0

我有Wild Card Subdomains,但是我只是不知道mod_rewrite到需要写入的程度。任何人都可以告诉我如何使它除了WWW以外的任何东西,没有什么去主站点,但任何其他的子域去/script/index.php?username=$username?Mod重写使用通配符卡子域名?

+0

您的意思是“有谁能告诉我如何使www和没有什么去主网站...”吗? – TimB 2008-10-23 04:11:50

回答

1

$ username变量应该来自哪里?

假设主站点的URL为http://www.example.com/main_site.php,并且您正在使用此外部目录上下文(即不在.htaccess中,也不在< Directory>指令中)。如果它在.htaccess中,请删除前导/(例如,仅使其成为main_site.php)。

我认为这不会马上工作,因为有很多非明确的变量(用户名是从哪里来的?,对请求的其余部分做什么,将它作为参数传递?是这个htaccess或主配置?),但希望能给你一个想法:

#Turn on the rewrite engine 
RewriteEngine On 
#Check accessed domain, if it's either www.example.com or 
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC,OR] 
#example.com 
RewriteCond %{HTTP_HOST} ^example.com$ [NC] 
#and the requested URL does not contain script you'll be accessing to avoid looping 
RewriteCond %{REQUEST_URI} !main_site.php 
#Then we tell that everything matching the above will go to main_site.php 
RewriteRule^/main_site.php [L] 
#If the request is not asking for main_site.php nor index.php 
RewriteCond %{REQUEST_URI} !main_site.php 
RewriteCond %{REQUEST_URI} !index.php 
#We go to /script/index.php (username will be empty, becase we don't know 
#where to get it from) 
RewriteRule^/script/index.php?username=$username [L] 
+0

用户名来自子域。 – Darren22 2008-10-23 19:02:59