我正在从一个基于php的旧网站转移到一个基于wordpress的新网站。在此过程中,我们正在摆脱很多不必要的页面。
但是,某些页面显示在Google上,我想通过使用301重定向到现在在新网站上包含相同信息的页面来避免403或404错误。
我目前的 .htaccess 显示:
# Switch rewrite engine off in case this was installed under HostPay.
RewriteEngine Off
SetEnv DEFAULT_PHP_VERSION 53
DirectoryIndex index.cgi index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
我想知道进行 301 重定向的最佳方法是什么? 将它们放在代码之前或之后只会给出 404 错误。
这应该有效;
重定向 301/old/old.htm http://www.website.com/new.htm
在
索引之前放置与此类似的规则.php重写规则应该有效:
RewriteRule ^(.*)$ http://newwebsite.com/$1 [R=301,L]
你可以在它前面放一堆RewriteCond,只捕获那些有问题的页面。
对于您在评论中发布的特定情况,此规则有效:
RewriteRule ^why-choose-us.* about-us [R=301,L]