可以';t执行正确的重定向301


Can't do a proper Redirect 301

我需要将301从旧域重定向到新域。我在.htaccess:中尝试了以下操作

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.com$[NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$[NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,NC,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}' /([^/]+/)*(default|index)'.(html|php|htm)' HTTP/ [NC]
RewriteRule ^(([^/]+/)*)(default|main|index)'.(html|php|htm)$ http://www.newdomain.com/$1 [R=301,NC]
Redirect 301 /folder/ http://www.newdomain.com
Redirect 301 /folder http://www.newdomain.com
Redirect 301 /folder/another-folder http://www.newdomain.com/new-folder/new-other-folder
Redirect 301 /folder/another-folder/ http://www.newdomain.com/new-folder/new-other-folder
Redirect 301 /folder/product.html http://www.newdomain.com/product
Redirect 301 /folder/other-product.html http://www.newdomain.com/new-other-product
</IfModule>

但它并没有被正确地重定向到上面代码中指定的每个页面或文件夹。我的旧网站在一个文件夹中。我正在使用Magento,需要重定向大约200页。我需要将文件夹中的旧域重定向到新的域根目录,并将所有页面和文件夹重定向到新域中的相应页面和文件夹。我怎样才能做到这一点?

避免将Redirect指令与RewriteRule混合。

您可以使用:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}' /([^/]+/)*(default|index)'.(html|php|htm)' HTTP/ [NC]
RewriteRule ^(([^/]+/)*)(default|main|index)'.(html|php|htm)$ http://www.newdomain.com.br/$1 [R=301,NC]
RewriteRule ^folder/?$ http://www.newdomain.com.br [L,NC,R=301]
RewriteRule ^folder/another-folder/?$ http://www.newdomain.com.br/new-folder/new-other-folder [L,NC,R=301]
RewriteRule ^folder/product'.html$ http://www.newdomain.com.br/product [L,NC,R=301]
RewriteRule ^folder/other-product'.html$ http://www.newdomain.com.br/new-other-product [L,NC,R=301]
RewriteCond %{HTTP_HOST} ^(www'.)?olddomain'.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com.br/$1 [R=301,NE,L]