简体   繁体   中英

301 redirects and wordpress pretty permalinks

I am moving from an old php based site to a new one based on wordpress. In the process we are getting rid of quite a few unnecessary pages.

However some of the pages are showing on google, and I want to avoid 403 or 404 errors by using 301 redirects to pages now containing the same info on the new site.

My current .htaccess shows:

# 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

and I was wondering what the best way to do 301 redirects is? putting them before or after the code just gives a 404 error.

This should work;

redirect 301 /old/old.htm http://www.website.com/new.htm

Putting a rule similar to this before the index.php rewrite rules should work:

RewriteRule ^(.*)$ http://newwebsite.com/$1 [R=301,L]

You can put a bunch of RewriteCond's before it to catch only those pages with issues.

For the specific case you posted in the comments, this rule works:

RewriteRule ^why-choose-us.* about-us [R=301,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM