Fixing WordPress index.php URL Redirection issue

Share this:

I recently found out that some of the older permalink of my blog that had index.php/%year%/%postname%/ was no longer redirecting to my new simple /%postname%/ URL. For some reason, the redirection plugin that I was using isn’t working anymore. As such, I figured that I could just use a generic redirect rule in the .htaccess file and get all the post redirected to the current permalink URLs.

Long story short, I found a nice redirect rule generator that’s provided by Yoast, the creator of the popular SEO WordPress plugin. You can find it here: https://yoast.com/research/permalink-helper.php.

Fixing WordPress index.php URL Redirection

Using it is really simple as it’s pretty much self descriptive on what you need to provide. But I’ve captured what I required for my site as per the screenshot below. You’ll see that my old permalink URL was based on an old Windows server with IIS setup where you see the index.php being shown on the URL.

Fixing WordPress index.php URL Redirection issue

Yoast Redirect Generator

Once you’ve entered the relevant data required, click on Generate Redirect and you’ll see the following.

Fixing WordPress index.php URL Redirection issue

Generated redirection rule

This will get you a redirection from https://www.atpeaz.com/index.php/2012/automaticlly-eject-external-disks-on-sleep-reconnect-after-os-x/ to https://www.atpeaz.com/automaticlly-eject-external-disks-on-sleep-reconnect-after-os-x/ which is exactly what I want. But I’ve also noticed that some sites have linked my old URLs without an ending backlash (/) and this rule would not work with links like that. So I just added another rule that would match that. Of course, edit the domain name as per your site’s.

RedirectMatch 301 ^/index.php/([0-9]{4})/([^/]+)$ https://www.atpeaz.com/$2
RedirectMatch 301 ^/index.php/([0-9]{4})/([^/]+)/$ https://www.atpeaz.com/$2

Adding the redirect rule to .htaccess

So what you now need to do is to just add that rule into your .htaccess file. If you’re familiar with SSH and editing your .htaccess file directly, just go ahead and add that rule in. However, if you rather not do that, you can search for WordPress plugins that allows you to edit the file directly from the WordPress Administration console. I used the Yoast SEO plugin to do that. The plugin includes a file editor that you can find in the Tools section.

Yoast SEO tools

Yoast SEO tools

Yoast file Editor

Yoast file Editor

Updating the htaccess file

Updating the htaccess file

Once done, you should find the old permalinks redirecting to the new URL format. Hope this helps you as it has for me.

Share this:

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.