We work with clients and projects of all kinds, and a frequent task we have to complete during a redesign or SEO overhaul is batch redirect a number of different pages from the old URL to the new, often SEO-optimized URL, without losing any of the existing SEO value from the old version of the same page. Many times, a project will benefit SEO-wise by changing the name or URL of a certain page, or by changing its domain name altogether -- however, this is only truly achieved if one is able to properly redirect any requests from the old domain or page to the replacement, new domain or page. Most people working in the sphere of web development will be able to tell you that creating a 301 Redirect is the best way to preserve the SEO “link juice” from your old page or site and apply it to the corresponding replacement URL. Creating 301 Redirects for one or a handful of pages, or even an entire domain, is relatively simple and straightforward and can be accomplished in a short period of time. Even when you have a number of pages to redirect, it can usually be accomplished by writing a “Catch All” rule using regular expressions that redirect any requests to a series of URLs that match a certain pattern -- for example, if all of your Blog Posts had URLs in a format like this: WWW.EXAMPLE.COM/blog/POST-NAME-HERE. It would be easy to redirect blog posts that have this URL format because each URL includes keyword “/blog/”, which can serve as a pattern that, when matched by a redirect rule, would properly trigger a redirect on any page that contains that “/blog/” keyword in the correct position in the URL.
Things begin to get complicated when you need to create 301 Redirects for a large number of URLs and none of the URLs have any discernible pattern to test matches against like we see in the above example. Recently, we had a client approach us with a need to redirect over 300 individual Blog Posts on their Wordpress website. The issue was, the permalink structure and URL format for all of their Blog Posts was simply the “Post Name” option on the Wordpress Permalink Settings screen, which yields a URL structure like this: WWW.EXAMPLE.COM/POST-NAME-HERE.
For this project, the client needed all 300+ Blog Posts to be 301 Redirected from the above format to WWW.EXAMPLE.COM/blog/POST-NAME-HERE. Essentially, we were being asked to change the Permalink Settings for Posts from the “Post Name” option to the “Custom Structure” option, and then create corresponding redirects to preserve any SEO value garnered by the old “Post Name” version of the Post Permalink URLs. This created an issue because their Blog Posts and all of the 125+ other static pages on their website adhered to the exact same URL and permalink structure -- attempting to write one “Catch All” rule to redirect all of the Blog posts would inadvertently redirect all of the static pages to the “/blog/” subdirectory as well, which would result in 404 Page Not Found errors being that the static page URLs were to remain, well, static and unchanged from their original format. This was an unusual problem to say the least, and the traditional way to do this would have been to manually type out and test 300+ individual 301 Redirect rules in an Apache .htaccess file. Needless to say, this seemed to be both tedious, inefficient and ripe with opportunities for errors to be made.
Luckily, this client was running their site on Wordpress, and we figured out a way to leverage the existing features of two well supported and well documented Wordpress plugins to batch process all 300+ redirect -- the key plugins that facilitate this process are Yoast SEO and Redirection by John Godley. If you’re following this guide for your own project, go ahead and get started by installing these two plugins as the first step hinges on you having Yoast installed.
The first step is to get an XML Sitemap of all of the Blog Posts that need redirection. Yoast SEO helps us do this by offering an XML Sitemap setting. Go to the “General” settings page under the Yoast SEO navigation tab in your Wordpress Admin Dashboard and make sure that the “XML Sitemaps” setting is set to “On.” Once that is complete, you should be able to easily get an XML Sitemap of all of your posts by visiting the sitemap URL that is auto-generated by Yoast. It will be in this format: WWW.EXAMPLE.COM/post-sitemap.xml -- visit that page in your browser and right click to “Save As” so you can download this XML file to your computer. As you might be able to tell from the name of this XML file, this Sitemap is for the Blog Posts only, which is exactly what we want and need for this situation.
The next step is to convert your XML Sitemap into a CSV (comma separated value) file. CSV files are like a simplified version of a Microsoft Excel file, and CSV is the format we need to feed back into the Wordpress Admin Dashboard in order to automatically create all of the Post redirects. We used this website to easily and quickly convert our XML file to a CSV file for free
Once you have your CSV file, open it up in Excel or Google Sheets in order to edit it. You’re going to need to format this CSV file in order to process the redirects properly. Start by removing the header rows that contain titles for the different columns. Next, make sure your old Blog Post URLs all fall in the first column. Then you will want to put the new Blog Post URLs in the second column so they line up with their out-of-date counterparts in the first column. We accomplished this by copying the first column to the second column, and then running a “Find & Replace” search to convert all instances of “WWW.EXAMPLE.COM/” to “WWW.EXAMPLE.COM/blog/”. When you’ve finished editing this file as such, save it as a CSV for use in the next step.
The last step is to create the 301 Redirects using John Godley’s Redirection Plugin. Since you’ve already installed and activated this plugin, you will be able to find it’s interface by going to the “Tools” tab in the Wordpress Dashboard and clicking the option “Redirection” at the bottom. Once you’re in the Redirection plugin Admin screen, you’ll see some links / tabs near the top -- you should be on the “Redirects” tab when you first load this page up. Click the tab inline with “Redirects” that says “Import/Export.” Here, you’ll be able to see a large Drag & Drop area which you can use to upload the CSV file you just created with the two columns of old and new Post URLs. Follow the instructions that come next from the plugin -- the default redirect option should be a 301 or permanent redirect, which is what you’ll want for this situation. The plugin also offers lots of other neat features such as creating pass through redirects and exporting your rules for use in other applications.
If you need help with creating redirects in Wordpress or otherwise, or just want to discuss your website or project with a team of seasoned professionals, please feel free to Contact Us or email us at firstname.lastname@example.org