How to have Custom Error Pages with XAMPP / Apache using .htaccess
So you want custom error pages on Apache on your production machine and/or
on XAMPP for windows on your dev machine. This can be achieved by using
.htaccess file.
Custom Error Pages on Xampp on Development Machine
Lets assume that your folder (website) is example.com
and your xampp is
installed on F:
.
- Create/Edit the file in
F:\xampp\htdocs\example.com\.htaccess
- Insert a line ErrorDocument 404 /example.com/404.shtml
- Create the file
F:\xampp\htdocs\example.com\404.shtml
- Put whatever html you want in it.
- Repeat for other errors, such as 400,403 and 500.
- If you type in localhost/example.com/xxy and xxy.php and xxy.html do not exist
then the error page will be shown
Custom Error Pages on Apache on Production Machine
Lets assume that your website is example.com
.
- Create/Edit the file in
public_html/.htaccess
- Insert a line ErrorDocument 404 /404.shtml
- Create the file
public_html/404.shtml
- Put whatever html you want in it. Note that it's best to have absolute paths to
any resources in these files. This is because they could be executed a subfolder.
- Repeat for other errors, such as 400,403 and 500.
- If you type in example.com/xxy and xxy.php and xxy.html do not exist then the error page will be shown
If you found this useful, then please consider making a donation.
Please donate if helpful