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?

Read More

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

Related posts

3 comments

  1. I think the old permalinks is stored in the table postmeta with the meta_key of _wp_old_slug

    If you wanted to clear all of the old slugs you could use this:

    DELETE FROM wp_postmeta WHERE meta_key = '_wp_old_slug';
    
  2. 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):

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

  3. Why aren’t the old permalinks redirecting to the new one?

    Each time you add new permalink structure and flush rewrite rules, WordPress doesn’t redirect old links to new links. Instead, WordPress will alter the old links with the new links completely.

    All past versions of the permalinks I used are still working.

    In WordPress, a URL doesn’t map to route. It’s looped through rewrite rules to find a match – a real URL which can be translated into database queries by parse_request method.

    It means that if the old rewrite rules which match old links aren’t removed. The old links still work.

    How can I remove old permalinks from being found by Google?

    Since they have been indexed by Google, I think permanent redirects is the best solution.

    I assume you’re using Apache, if not, please let me know.

    In your case, just add following code before WordPress rules in your .htaccess file:

    RewriteEngine On
    RewriteRule "^shop/(.+)/?$" "http://example.com/$1" [R=301,L]
    

Comments are closed.