WordPress and Redirect plugin – Server 404 Passthrough

If you’re using WordPress and it happened that you moved from one domain to another, or you just changed the URLs to make them more readable, easy to remember, or just different you probably don’t want to lose the search engines indexing you hardly got!

In this case, you can use one of the many WordPress plugins to achieve this result, and I would like to suggest Redirection by John Godley due to its simplicity to use, the fact that it’s free, and the great features it provides as the import/export through JSON files.

I won’t talk about how to install it, how to use it, and anything else about the plugin, because it’s not the article’s purpose, and because it’s super easy too.

The Context

I would like instead to show what I faced when I tried to redirect my old website URLs to the new ones I have on this renewed website. Let’s consider that I’m using the same domain, but I had a Joomla installation into a subfolder named /site/ and now my WordPress is installed into a subfolder named /wp/.

I had to redirect this kind of URLs:

https://texnostuff.com/site/name-of-the-article-url

into this other kind of URLs where also the language name is present:

https://texnostuff.com/wp/en/name-of-the-article-url-but-bit-more-fancy

This was super easy with the Redirection by John Godley plugin, but I didn’t see any result and every time I was writing the old URLs into the browser address bar or testing the redirect directly through the plugin, I was receiving a 404 response:

Redirect issue shown by the Redirection plugin
Redirect issue shown by the Redirection plugin.

Something that triggered my attention, was the 404 Error Page wasn’t the one provided by WordPress, but it was dispatched directly by the webserver!

The Issue

Thanks to this I did some test to find the problem and I saw that if a not existing URL was pointing at least inside the /wp/ folder, the 404 Error page was provided by WordPress, otherwise directly by the Web Server.

The Solution

The solution I applied is to intercept all the 404 Errors on the http://texnostuff.com domain and redirect them to WordPress. In this way, if the requested URL has been added to the Redirection plugin it is managed by it, otherwise the WordPress 404 Error Page is shown.

How to apply the solution

Access to the webserver where WordPress is installed, and look for the .htaccess file in the public_html root folder:

Webserver where WordPress is installed (into the public_html/wp/ folder).

Open the .htaccess file with a text editor and add the following lines of code into it. As I’m using cPanel I could modify directly the file online.

Code to be added into .htaccess file

With those lines of code we’re telling to the engine that in case of Error 404 it should look for the error document into the folder /wp/, and doing this, the 404 Error management is demanded to WordPress and the Redirection plugin if configured to do so.

Verify the Solution

To confirm the resolution, just go back to the Redirection plugin and test some of the redirection rules you have:

Double Redirection, one due to the Polylang and one due to the Redirection plugin.
Single redirection by the Redirection plugin.
A temporary (code 307) redirection by the Redirection plugin.

lu122131

Luca Bortolotti Lentsch Engineer And Photographer From Lombardia Currently in Friuli Venezia Giulia #lu122131ph