2011-11-17 53 views
1

我想將http://sub.domain.com重定向到http://www.sub.domain.com,但也有http://domain.com重定向到http://www.domain.com將子域重寫爲www對應

這就是我對域部分

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC] 
RewriteRule .? http://www.domain.com%{REQUEST_URI} [R=301,L] 

有多難這個做什麼?

+3

這是解決方案:!的RewriteCond%{HTTP_HOST}^$ 的RewriteCond%{HTTP_HOST}^WWW \。 [數控] RewriteCond%{HTTPS} s^on(s)| RewriteRule^http%1://www.% {HTTP_HOST}%{REQUEST_URI} [R = 301,L] –

+0

請添加評論作爲回答。這似乎是正確的。 – Gerben

回答

6

這裏是解決方案:

RewriteCond %{HTTP_HOST} !^$ 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTPS}s ^on(s)| 
RewriteRule^http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]