Click on the banner to learn about and purchase my database training on Azure

HTTP error redirection using .htaccess (Apache)

Views: 4.945 views
Reading Time: <1 minutes

Staff,
Good evening.

Today I will show you how to redirect your applications in case of a URL typo, for example, where the Apache web server usually displays an error message and the visitor may have difficulty returning to your site. If he found your site through a search engine (aka Google), he will probably leave your site and go back to Google. We can't let that happen, correct?

Once again, I will turn to our great ally, the Apache HTTP Server settings file, .htaccess to help us.

To create the redirect, let's use the directive ErrorDocument, as we can see in the example below:

This will ensure that for each HTTP error code, you have control over how you want to handle it. When the user types an invalid or non-existent URL (Error 404 - Not Found), I am redirecting to the URL /apache.php?error=404. Inside the apache.php file I do the necessary treatments, personalization and visual art so that the visitor reads a friendly message informing that the page does not exist and suggesting other URLs, using the layout of my website and several links available for him to browse. usually.

Thus, we even conquered visitors coming from broken links or mistakes! Oh, do you need help identifying HTTP error codes? Learn more here.
To the next.