htaccess的301重定向

问题描述:

我想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

确定...我想通了这一点 - 在第二种情况下工作 - 只需要之后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]