How to Specify Error Pages (Such as 404) Using .htaccess
Introduction
Apache's ErrorDocument directive replaces the default error response with your own page, a text string, or a redirect to a local or external URL.
Creating Custom Error Pages
Use SSH to connect to your server and navigate to the website document root location. Use your favourite text editor to create an error page named 404.html with the sample contents as shown below.
<html> <head> <title> Custom 404 Error Page</title> </head> <body> <p> The resource you tried is currently unavailable in server, please navigate back and try other products.</p> </body> </html>
Assign proper permission for the file,
chmod 644 404.html chown user.user 404.html
Configuring Web Server to Use Custom Error Page
Syntax:
ErrorDocument error-code [path to error document]
Example, with 404.html in the document root:
ErrorDocument 404 /404.html
The error document directive can be added to the virtualhost section of your website.
Open the httpd.conf using a text editor, find the virtual host section of your website.
<VirtualHost *:80>
ServerName mydomain.com
…..
….
…
..
.
ErrorDocument 404 /404.html
</VirtualHost>
The same line can be placed in the .htaccess file of the document root when AllowOverride FileInfo is enabled for that directory, which is the usual case on cPanel and Plesk servers.
Test Apache configuration and reload it to make the error document in effect.
From the EuroVPS FAQ.
More in how toYour next infrastructure partner
Still have
a question?
Tell us what you are trying to do. An engineer will read it and reply.
+357 222 32280
who will look after your infrastructure.
Let’s start with your setup.
A little context helps us start the right conversation.
