Create Custom Error Pages Using the .htaccess File For WordPress
June 11th, 2017 | by Ravi Chahar || Leave a comment |
If you’re using WordPress then having a few errors isn’t a new thing for you. Every website users see an error page at some point. Have you ever thought to modify those messages?
You would be happy to know that you can create custom pages using the .htaccess file. I am sure, you know the power of this file.
You can also use the .htaccess file for your WordPress website security. But here, you just have to use it for better user experience.
Every WordPress directory has some static HTML files for the different errors. If not, you can create those files.
Though you can create custom error pages from the cPanel still, you should know the alternatives.
Start Editing the .htaccess File from the Root Directory
I am sure, you would know where to find the .htaccess file of your WordPress website.
You have to open the file manager and don’t forget to enable showing the hidden files. It’s because the dot as the prefix for this file signifies that it’s hidden.
Many people get confused when they don’t find any such file in the root directory.
You can enable it from the settings of the file manager.
If you don’t see this file even after that, you can create a new .htaccess file. It’s just a text file. Just create it and upload it or you can create it using an option from the main navigation menu.
Before I go further, let me mention some errors.
- 404 error
- 500 error
- 403 error
- 503 error
There may be many other errors too.
As mentioned earlier, for each error, you may find a static HTML file. But if not, then you can control the output of the error page using the .htaccess file.
Actually, you can add a backup. If the static file fails, your custom error message will appear.
Add the code in the file.
ErrorDocument 404 “<H1>This Page Has Been Shifted</H1>”
There are two lines, the first one has the customer error message and the second one will show the default 404 error message.
You can do that for all the errors. Suppose you want to create a custom error page for 403 forbidden error.
ErrorDocument 403 “<H1>You aren’t authorized to see this page</H1>”
You can show any message you want. If you know a little bit about the HTML language, you can easily create custom error pages using the .htaccess file.
The same goes for all the other error pages.
ErrorDocument 500 “<H1>The server is down for a while or not able to handle your request</H1>”
The default error HTML files may have a different extension. It can be .shtml too.
Why is it Important to Create Custom Error Pages
You should understand the concept of user experience. Sometimes, due to the absence of the error HTML files, your users see a blank page instead of the error messages.
It will directly impact your online brand. People seek for a reliable source to get the proper information.
In case, your website is down or you have shifted the page, either you redirect or show an error message so that your readers can come to know about it.
It’s all about maintaining your personal brand and providing the best user experience.
Can You Now Create Custom Pages Using the .htaccess File
It can be hard for the non-techie people still you have an alternative. You should know the power of this amazing file.
The .htaccess file is one of the most important files of your WordPress website. I always recommend you to learn more about using the codes instead of replying to others.
I am sure, after going through this tutorial, you can easily create custom error pages using the .htaccess file. If you still have any doubt, feel free to ask.