Remove Old Permalinks? - wordpress

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

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';

As you can see, Wordpress doesn't handle redirections when you change your permalinks structure. There is 2 ways to handle this, through:
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.
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

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]

Related

How to 301 redirect for tags and categories in wordpress?

Hi Please sorry if my question was simple or very basic. But please some one tell me how to fix this problem
i need to redirect all my website pages and post from old url to new one
example :
blog.mysite.com/posttitle.html
301 redirect to
mysite.com/blog/posttitle.html
Already some rule written in htaccess but it only redirects blog posts and pages.
301 redirection is made only for the blog post and pages. But not for all tags, all Categories and all author pages. the following pages are not redirecting ,
blog.mysite.com/tag/mytagname
blog.mysite.com/categories/categoriesname
blog.mysite.com/author/authorname
how to redirect this to new site
mysite.com/blog/tag/mytagname
mysite.com/blog/categories/categoriesname
mysite.com/blog/author/authorname
There are plugins that can take care of all this for you. No messing with .htaccess. All done by modifying WordPress own rewrite rules
https://wordpress.org/plugins/redirection/
https://wordpress.org/plugins/quick-pagepost-redirect-plugin/
https://wordpress.org/plugins/simple-301-redirects/
If you want to do yourself try adding this to your .htaccess
RewriteEngine on
RewriteRule ^(.*)$ http://your-site.com/blog/$1 [R=301,
This would go before the WordPress specific part of .htaccess 'begin WordPress'. That section can be overwritten by WordPress automatically.

Wordpress permalink / previous URL issue

My work has recently converted their website to run on Wordpress. The old website was made in ASP. Our marketing department have advertised a specific URL for an event, but now that URL has changed.
The old URL is: /who-are-you/stem-intro.aspx
The new URL is: /stem2014/
Can I used my htaccess file to make the first URL go to the second url without an .aspx file existing?
Thank you for your help.
Yes you can use this rule on top of your WP .htaccess (just below RewriteEngine line):
RewriteRule ^who-are-you/stem-intro\.aspx$ /stem2014/ [L,NC,R=301]
Can be performed easily with a 301 redirect in .htacess, especially if this is a one off thing
Redirect 301 /who-are-you/stem-intro.aspx http://www.YOURSITE.com/stem2014/

Wordpress 301 Redirects for thousands of posts

I have a site with more than 2000 links beeing redirected in my .htaccess file.
I would like to restructure my htaccess, so the 301 redirections work faster, and also do not loose any SEO.
Let's say I have 2 categories in my blog.
mysite.com/blog/old_planes
mysite.com/blog/old_cars
that I want to redirect to
mysite.com/blog/new_planes
mysite.com/blog/new_cars
For each category I have a number of posts. How should I redirect them? I mean should I redirect each post and after that the category?
Redirect 301 /blog/old_planes/747 http://www.mysite.com/blog/new_planes/747
Redirect 301 /blog/old_planes http://www.mysite.com/blog/new_planes
or first redirect the category and then the posts? I want them all to work. Most important I do not want any "NOT FOUNDS" in webmaster tools.
Does the order matter?
If I want latter to add a new redirect should I search the specific category and paste it there? Or should I paste it at the end of my 2000 redirects.
For redirections, yes you can manually update your htaccess file, but I have been using a plugin that seems to fit the bill on a few sites - it makes tracking changes a lot easier in a convenient admin panel:
http://wordpress.org/plugins/redirection/
Simply doing:
Redirect 301 /blog/old_cars /blog/new_cars
Redirect 301 /blog/old_planes /blog/new_planes
Is all that you need. Anything after the old_cars/ and old_plans/ will automatically show up in the new destination. However, since this is wordpress, you've probably got some mod_rewrite rules in your htaccess file, and these redirects will interfere with how that works. So instead, you should use mod_rewrite and add these rules before your wordpress rules:
RewriteRule ^blog/old_cars(.*)$ /blog/new_cars$1 [L,R=301]
RewriteRule ^blog/old_planes(.*)$ /blog/new_planes$1 [L,R=301]

Wordpress Blog URL

For some reason my blog posts are creating their own URL's.
Blog is on www.website.com/blog/ but when I make a new post, the new post URL is www.website.com/new-post-url/.
What I want is for the blog posts URL to be www.website.com/blog/new-post-url/ as their URL.
I use All in One SEO as my SEO plugin (if that matters).
You should check your blog setting.
login as administrator and go Settings >> General Settings
check here Site Address (URL). This should be http://www.website.com/blog
Hope this is helpful.
all the best ;)
#user1667462
Have you checked your .htaccess file?
Because you when you're having /blog kind of redirect to your WordPress Blog then you must have to add below code in your .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?website.com$
RewriteRule ^(/)?$ blog [L]
Go to Settings -> PermaLinks from Dashboard and select Custom Structure
give /blog/%postname%/
Check your blog by going to any post/page.
Log into your Wordpress admin panel and check to ensure that permalinks are set to the appropriate settings. Also check to make sure that your theme is not overriding the settings you might have chosen. Some themes for example can explicitly request you set a blog page for the blog posting which can interfere with what you assume to be happening.
Your go to admin page and click setting page, change the url types.

Moving Wordpress to another domain with different permalinks

I want to move Wordpress to another domain and also change the permalinks. So basically what I want is to move from: oldsite.com/PostId-PostName.html to newsite.com/PostName/
I know this can be done from .htaccess, but I don't manage to get it right. Can you please help me ?
This is how it can be done using Apache's mod_rewrite:
# Activate Rewrite Engine
RewriteEngine On
# redirect posts to new site
RewriteRule ^(\d+)-([^/]+)\.html http://www.newsite.com/$2/ [R=301,NC,QSA,L]
This will ONLY redirect URLs like oldsite.com/12345-very-interesting-post.html.
There is a Codex article dedicated to this: Moving WordPress

Resources