2008-10-23 63 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