I recently installed a new WordPress site as a replacement for an older site and I needed to redirect the old pages to the new site. I installed the WordPress redirection plugin in order to do this as it looked well supported and feature rich.
In the past I’ve always used the .htaccess file for redirects as it’s simple to set up if you have mod_rewrite enabled in Apache. The downside of this approach of course is that you don’t know if your redirects are being used. For popular articles it’s going to be obvious – you’d see a drop in impressions – but for less popular pages it can be difficult to know if it’s worth keeping the redirect around. That’s where the redirection plugin comes in, it tracks the number of hits a particular redirect has received and when the last hit was.
WordPress Redirection Plugin Loop Problem
One really nice feature of the redirection plugin is the ability to upload an existing .htaccess file and have it read all the redirections out of it. I grabbed the .htaccess from my old site and fed it to the redirection plugin only to find a bit of a problem. Suddenly every page on my site was causing a redirection loop.
I was left scratching my head because from what I could see all the redirections listed were perfectly valid so I fired up MySQL Workbench and had a look in the database. What was at the top of the redirection table…
Having a URL setting of /.* means that it will catch absolutely every page on the site and it’ll redirect them to /index.php which, of course, will match the URL and around we go again. Fixing this was just a matter of finding the offending entry in redirection table and deleting it. I presume something in my .htaccess file tripped up the import process, it would be nice if the plugin could filter for this situation though.
WordPress Redirection Plugin Group Problem
The redirection plugin allows you to group redirects and 404’s to make them easier to manage. This is great but there’s a bit of missing functionality, once a redirection has been created you can’t then assign it to a different group. Fortunately the layout of the redirections in the database is simple and clear so a simple SQL query can easily fix the problem. I’ll be using MySQL Workbench for this but there are plenty of other options. First open the wp_redirection_items table and ensure that you can see all the redirections and in particular the group_id column as that is the one that we’ll be modifying.
Now open the wp_redirection_groups table:
The id at the start of each row is what we are interested in it corresponds to the group_id in the wp_redirection_items table. Note the id of the the group you would like to populate with redirections. Now comes the part where I can’t provide complete help as your selection criteria for moving items over will be different to mine. My redirects are currently split naturally into two groups that go to different domains hence the groups entries in the groups table. I can filter out entries based on the first part of the action_data entry in the items table. The query I used was this:
UPDATE wp_redirection_items SET group_id = 4 WHERE action_data LIKE 'http://www.example.com/index.php%'; SELECT * FROM wp_redirection_items WHERE action_data LIKE 'http://www.example.com/index.php%';
The second query is simply there to confirm that the update took place as expected.