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
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.
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.
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:As you can see, Wordpress doesn't handle redirections when you change your permalinks structure. There is 2 ways to handle this, through:
If
.com/lightbulb
is the new path and.com/shop/lightbul
the old one:But if you want to redirect old permalink structure
.com/shop/
to main domain your.htaccess
rules will be: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
I think the old permalinks is stored in the table
postmeta
with themeta_key
of_wp_old_slug
If you wanted to clear all of the old slugs you could use this: