使用.htaccess重写所有子域URL

时间:2013-11-04 14:50:41

标签: apache .htaccess mod-rewrite url-rewriting

我有一个域test.com和一个子域sub.test.com

现在,我需要将网址sub.test.com重写为test.com/?state=sub,将sub.test.com/content/改为test.com/content/?state=sub,将sub.test.com/content/proceed/改为{{1} }。

第一个网址的规则有效,如下所示:

test.com/content/proceed/?state=sub

知道怎么做吗?

1 个答案:

答案 0 :(得分: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]