2013-11-04 114 views
0

我有一個域test.com和一個子域sub.test.com使用.htaccess重寫所有子域URL

現在,我需要的URL sub.test.comtest.com/?state=sub,像sub.test.com/content/test.com/content/?state=sub的URL,並sub.test.com/content/proceed/改寫爲test.com/content/proceed/?state=sub

第一個URL規則的工作,這樣的事情:

RewriteCond %{HTTP_HOST} !^www\.test\.com 
RewriteCond %{HTTP_HOST} !^webmail\.test\.com 
RewriteCond %{HTTP_HOST} !^m\.test\.com 
RewriteCond %{HTTP_HOST} ([^.]+)\.test\.com 
RewriteCond %{REQUEST_URI} !^/index\.php$ 
RewriteCond %{REQUEST_URI} !robots.txt.* 
RewriteRule ^$ http://www.test.com/?state=%1 [P] 

任何想法如何做到這一點?

回答

0

此規則應該爲你工作:

RewriteCond %{HTTP_HOST} !^(?:www|webmail|m)\.test\.com$ [NC] 
RewriteCond %{HTTP_HOST} ([^.]+)\.test\.com$ [NC] 
RewriteCond %{REQUEST_URI} !^/(index\.php|robots\.txt) [NC] 
RewriteRule^http://www.test.com%{REQUEST_URI}/?state=%1 [P]