Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
780 views
in Technique[技术] by (71.8m points)

wordpress - Remove Old Permalinks?

I have a Wordpress website. I have changed my permalinks several times. All past versions of the permalinks I used are still working. If I type them into the URL bar, I am taken to the page WITHOUT the URL changing/redirecting to the new/current permalink.

Why aren't the old permalinks redirecting to the new one?

This is causing issues with Google reading duplicate content.

Example: .com/lightbulb .com/shop/lightbulb

The second URL is old, but still works when I type it in.

Shouldn't it redirect to the new one?
How can I remove old permalinks from being found by Google?.

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As you can see, Wordpress doesn't handle redirections when you change your permalinks structure. There is 2 ways to handle this, through:

  1. The htaccess rewriting rules (manually editing the .htaccess file) depending on your new old/new permalinks structure.
    If .com/lightbulb is the new path and .com/shop/lightbul the old one:
Options -Indexes
Options -Multiviews
Options +FollowSymLinks 
<IfModule mod_rewrite.c>
  RewriteEngine on
  RedirectMatch 301 /shop/lightbulb(.*) /lightbulb$1
  # or
  # RewriteRule ^shop/lightbulb?(.*) http://www.domain.com/lightbulb$1 [R=301,L]
</IfModule>

But if you want to redirect old permalink structure .com/shop/ to main domain your .htaccess rules will be:

Options -Indexes
Options -Multiviews
Options +FollowSymLinks 
<IfModule mod_rewrite.c>
  RewriteEngine on
  RedirectMatch 301 /shop/(.*) /$1
  # or
  # RewriteRule ^shop/?(.*) http://www.domain.com/$1 
</IfModule>

Permanent redirection is used for best SEO practices, redirecting definitively old permalinks to new ones, avoiding duplicate content, and telling search engines that your old permalinks have been moved definitively to new ones.

  1. Redirection Wordpress free plugins (there is a lot):
    • Redirections plugin is the most popular and offer a easy-to-manage 301 redirections and 404 error tracking. It also offers more advanced tools to help you keep track of loose ends on your site like broken links and orphan pages.
    • Simple 301 redirects plugin is simple and deals with 301 redirect creation for when you’ve permanently moved content from one location to another.
    • Quick Page/Post Redirect plugin easily redirect pages/posts or custom post types to another page/post or external URL by specifying the redirect URL and type (301, 302, 307, meta).
    • Safe Redirect Manager plugin comes with an additional whitelist feature for added security…
    • SEO Redirection Plugin plugin offers support for generating 301, 302, and 307 redirects and also supports 404 error monitoring with easy one-click redirection…

Converting old path (urls) in database (if they still exist):

You can use Search and Replace free plugin, to easily find some old related urls or path in your database and bulk replace them by the new ones. This is a very powerful plugin, a little buggy, but working fine when you know it (but make always a backup before).

A recent reference:
A Simple Guide to Changing Your Permalinks Without Breaking Your WordPress Website


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...