2011-05-31 133 views
3

我想301重定向htaccess的301重定向

http://www.domain.com/page.html

http://subdomain.domain.com/page.html

,並試圖:

redirect 301 /page.html http://subdomain.domain.com/page.html 

問題是域和子域都指向相同的目錄,並使重定向的方式永遠不會完成。

也嘗試沒有成功:

RewriteCond %{HTTP_HOST} ^domain.com$ [OR] 
RewriteCond %{HTTP_HOST} ^www.domain.com$ 
RewriteRule ^page\.html$ "http\:\/\/subdomain\.domain\.com\/page\.html" [R=301,L] 
+0

所以這只是爲了虛榮呢?... – Fosco 2011-05-31 20:04:59

+0

你h ave mod_rewrite啓用了嗎?你是否寫過:RewriteEngine On,在這些規則之前? – reeaal 2011-05-31 20:20:37

+0

是mod_rewrite被啓用,我有RewriteEngine On。 在第一種情況下,我認爲它只是循環。 – venz 2011-05-31 21:16:05

回答

1

確定...我想通了這一點 - 在第二種情況下工作 - 只需要之後RewriteEngine敘述在放置:

RewriteCond %{HTTP_HOST} ^domain.com$ [OR] 
RewriteCond %{HTTP_HOST} ^www.domain.com$ 

RewriteRule ^page.html$ http://subdomain.domain.com/page.html [R=301,L] 

這可以用於多種規則在一個條件下:

RewriteCond %{HTTP_HOST} !^(www\.)?domain.com$ [NC] 
RewriteRule .* - [S=2] 

RewriteRule ^page.html$ http://subdomain.domain.com/page.html [R=301,L] 
RewriteRule ^page-2.html$ http://subdomain.domain.com/page-2.html [R=301,L]