A blog lives or dies by links. Almost half of Meandering Passages (MP) traffic comes from search engine links. Keeping inbound links valid is of upmost importance.
There are thousands of links pointing to Meandering Passage from Internet search engines and other internet blogs. These links accumulated over the three plus year life of this blog. There are also hundreds of internal links posted in MP pointing to related posts and self hosted images.
Meandering Passage hosting has changed twice with additional internal changes to its folder/file structure along the way, complicating the process of keeping older links valid.
I’ve been thinking of ways to manage these links while organizing and consolidating resources?
Here’s the two areas I’ve focus upon:
- External links coming into Meandering Passage from external sources; and
- Internal post links pointing to locally host image files.
External Links –
Invalid links happen and can best be handled by redirecting them, when possible, to the correct page or object. In my case I use the WP plugin tool Redirection to help with this. Redirection supports both WordPress-based and Apache-based redirections and 404 error monitoring–captures a log of 404 errors and allows you to easily map these to 301 redirects.
It also supports full regular expressions so you can map rules to handle multiple link common error issues. For example, the following redirection rule:
/wp-content/uploads/(.*) =mapped to=> /uploads/$1
redirects all links with ‘/wp_content/uploads/’ to the same URL only without the ‘/mp_content/’. In this way one rule may addresses multiple link errors. You can find more information on this at the Redirection link above.
Quick direct one-to-one link redirections can also be created from the 404 error log.
There are other redirect WP Plugin available which would probably work as well. Redirection just happens to be the one I’m familiar with.
Internal Post Links –
I host photos and images for Meandering Passage locally on the site. After this last move MP had images stored in three different folders:
(A) – ‘/wp/photos/’ – The original image folder, used when I first set-up MP;
(B) – ‘/wp-content/uploads/’ – A second image folder, created when I forgot to change a WP parameter during a move; and
(C) – ‘/photos/’ – The final and main image folder.
My final goal was to consolidate all the photos and images from (A) and (B) into (C) and change the links in the blog posts to point to the new locations. This makes it easier to keep track and manage the media files.
The first step was to copy all the images/photos from (A) and (B) into (C), maintaining the same internal (A)/(B) folder structure, paths and naming.
Step two was to change the image links in blog post content, pointing to (A) or (B), to point instead to the newly copied images in (C).
To accomplish this I used a MySQL Admin Tool and SQL. The tool I used was Navicat for MYSQL–a tool I already owned and am familiar with. There’s also the free phpMyAdmin tool.
WordPress post content is stored by default in file ‘wp_posts‘ and field ‘post_content‘. To change the image links two short SQL statements were created.
Important: You should always back-up your database before running any SQL statements.
The first statement changed the image links from (A) to (C);
UPDATE wp_posts SET post_content = REPLACE(post_content,’/wp/photos/‘,’/photos/‘);
and, the second statement changed the image links from (B) to (C);
UPDATE wp_posts SET post_content = REPLACE(post_content,’/wp-content/uploads/‘,’/photos/‘);
Notice in the ‘REPLACE’ function the first parameter was the ‘search_string’ and the second parameter was the ‘replacement_string’
These statements took less then 15 seconds each to run and correct all the internal image links.
Overview –
If you have a WP blog and have never moved it or changed any of the permalink parameters you probably do not have any major link issues.
In my case managing external links is an ongoing process, but if it brings a user to my site which would otherwise receive a 404, not-found, it’s worth it.
The internal image ink change was a one time fix to consolidate all MP images at one location for easier management.