Php Can';我不能做正确的重定向301

Php Can';我不能做正确的重定向301,php,.htaccess,magento,redirect,mod-rewrite,Php,.htaccess,Magento,Redirect,Mod Rewrite,我需要做一个重定向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.newdoma

我需要做一个重定向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>

选项+FollowSymLinks
重新启动发动机
RewriteCond%{HTTP_HOST}^olddomain.com$[NC,或]
RewriteCond%{HTTP_HOST}^www.olddomain.com$[NC]
重写规则^(.*)$http://www.newdomain.com/$1[R=301,北卡罗来纳州,北卡罗来纳州]
重写cond%{u请求}^[A-Z]{3,9}\/([^/]+/)*(默认|索引)\.(html | php | htm)\HTTP/[NC]
重写规则^([^/]+/)*)(默认值|主|索引)\(html | php | htm)$http://www.newdomain.com/$1[R=301,北卡罗来纳州]
重定向301/文件夹/http://www.newdomain.com
重定向301/文件夹http://www.newdomain.com
重定向301/文件夹/其他文件夹http://www.newdomain.com/new-folder/new-other-folder
重定向301/文件夹/另一个文件夹/http://www.newdomain.com/new-folder/new-other-folder
重定向301/folder/product.htmlhttp://www.newdomain.com/product
重定向301/folder/other-product.htmlhttp://www.newdomain.com/new-other-product
但是它没有被正确地重定向到上面代码中指定的每个页面或文件夹。我的旧站点位于文件夹中。
我正在使用Magento,需要重定向大约200页。我需要将文件夹中的旧域重定向到新域根目录,并将所有页面和文件夹重定向到新域中的相应页面和文件夹。如何实现这一点?

避免将
重定向
指令与
重写规则
混合使用

您可以使用:

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]

我按照你告诉我的那样试过了,但当我试着去www.olddomain.com/folder/other-folder时,它应该会带我去www.newdomain.com/new-folder/new-other-folder,但它会带我去www.newdomain.com/folder/other-folder。我的大多数文件夹、子文件夹和产品名称在新域上都有点不同。你能检查一下吗?不幸的是,情况还是这样。可能某些服务器配置正在干扰?1。缓存已清除。2.我忘了说你们是不同的主持人。新服务器/主机正在nginx上运行。
/folder/
是否有另一个.htaccess?是你的根。htaccess完全如我的答案所示?伙计,你救了我一天!My.htaccess位于/folder/中,根目录上还有另一个.htaccess。我把它改成了root,瞧!