cPanel/WHM custom 403 page for all accounts?

enjoylife

Member
May 9, 2011
13
0
51
how to custom 403,404,500 page for all accounts?i want to do it on server wide by cPanel/WHM. i want to do it on server side, to all the accounts on the server not a single user. thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello :)

This can be achieved by creating an alias for "/errorfolder" in the /usr/local/apache/conf/httpd.conf file via the following steps:

1) Create a directory in /usr/local/apache to store your custom error messages. In this case, I have named the directory "customerror":

Code:
mkdir /usr/local/apache/customerror
2) Ensure your custom error pages have been added to this directory (400.shtml, 404.shtml, etc).

3) In Web Host Manager, browse to:

"WHM Main >> Service Configuration >> Apache Configuration >> Include Editor"

4) Select "All Versions" under "Pre Virtual Host Include".

5) Add the following to the text box:

Code:
Alias /errorfolder /usr/local/apache/customerror/
ErrorDocument 400 /errorfolder/400.shtml
ErrorDocument 401 /errorfolder/401.shtml
ErrorDocument 403 /errorfolder/403.shtml
ErrorDocument 404 /errorfolder/404.shtml
ErrorDocument 500 /errorfolder/500.shtml
6) Click "Update", and then click "Restart Apache".

Your custom error pages will now be used by default.

Thank you :)
 

enjoylife

Member
May 9, 2011
13
0
51
1) Create a directory in /usr/local/apache to store your custom error messages. In this case, I have named the directory "customerror":
how to do this? and how to upload the error pages which created by me to the customerror file?

if the user want to overrite the error pages? could he overrite those error pages by his cpanel or .hactess. many thanks.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello :)

1) Create a directory in /usr/local/apache to store your custom error messages. In this case, I have named the directory "customerror":

how to do this? and how to upload the error pages which created by me to the customerror file?
Assuming you have root access to the server, this can be done via the command line using the command provided in my last response:

Code:
mkdir /usr/local/apache/customerror
More information on accessing your server via SSH can be found at:

SSH/Shell Access

The easiest method to create the files within this directory would likely be to create them through a command line text editor:

Code:
vi /usr/local/apache/customerror/404.shtml
If you are not familiar with using "vi", feel free to use the text editor of your choice (e.g. nano or pico)

if the user want to overrite the error pages? could he overrite those error pages by his cpanel or .hactess.
Yes, this can be achieved via "cPanel -- Advanced - Error Pages":

Error Pages

Thank you.
 

enjoylife

Member
May 9, 2011
13
0
51
many thanks,cPanelMichael . you made me know a lot. if i want to add some css and image in the 404.shtml. where should i put the image in, and how to upload the images which will be used on the 404.shtml?

i am sorry i am a newbie. can i write the css code in vi for the 404.shtml.

could i name it to 404.html not 404.shtml?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello :)

You can simply create an images directory within your error log directory. EX:

Code:
mkdir /usr/local/apache/customerror/images
You can upload the images via SFTP/SCP, or upload them to an account via FTP and move them to the directory through the command line using the "mv" command.

You can insert or edit CSS code into the error page using "vi" if you prefer, yes. If you want to name it 404.html, remember to update the entry used during steps 3-5 from my initial reply to:

Code:
ErrorDocument 404 /errorfolder/404.html
Thank you.
 

enjoylife

Member
May 9, 2011
13
0
51
i have created the images according to the code which you told me. when i used the FileZilla Client tool with user root and whose password via SFTP to upload the images. i didn't find the images file that i created in vi. i see some files eg:root->csf/public_ftp/cpanel3-skel...and so on. how could i can find the images file.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello :)

The images would be located in the directory you uploaded them to. You can not edit or create an image using a text editor such as "vi". You have to upload them to the directory, which if you used the example provided would be:

/usr/local/apache/customerror/images

Thank you.
 

enjoylife

Member
May 9, 2011
13
0
51
i am sorry, but when i access my WHM via SFTP with root, i can't find this directory
Code:
/usr/local/apache/customerror/images
the directoy i found like this:
root
csf
public_ftp
cpanel3-skel..
....and so on
i can't find the customerror/images file, so i don't know where should i upload my images to and how in vi to invoke it.eg:

Code:
<img src="">  
background:url(".....")...;
how to write the image path and the background image path?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello :)

You mentioned using FileZilla. In Filezilla, where it lists "Remote Site" on the right hand side, you can manually enter a directory such as:

/usr/local/apache

As for coding the page using HTML, the following URL should be useful for that:

HTML Tutorial

Thank you.
 

enjoylife

Member
May 9, 2011
13
0
51
got it. i find i don't necessary to code it.i can upload the file to customerror file directory. many many thanks!
 

enjoylife

Member
May 9, 2011
13
0
51
oh,damn it. the directory is as this:
Code:
/usr/local/apache/customerror/images
/usr/local/apache/customerror/404.shtml
style.css
the 404 page can' invoke the image and style.css. why? when i access a user's site which is on my server and doesn't overwrite the 404 page. the 404 page show no style and images,
 
Jan 28, 2011
8
0
51
Gomel, Belarus
Hello,

Custom error pages applied to every user account. But how to allow users to make their own error pages in this case? I'd like my error pages to be defined only for accounts who didn't make such pages.

Thanks for reply on advance.
 

leonep

Well-Known Member
Nov 18, 2014
228
18
68
Pescara
cPanel Access Level
Root Administrator
nice post !!
i followed instructions provided by micheal and it's ok.
All users have default error documents pages. But it's possible to manual modify .htaccess for 1 user that want a custom error doc page ? thanks
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
does not matter
with allowoverride option in apache conf it's possible to edit .htaccess and add following
ErrorDocument 404 /new404.html
I am happy to see you were able to determine the solution. Thank you for updating us with the outcome.
 

system-error

Member
Dec 16, 2014
21
1
3
cPanel Access Level
Root Administrator
I followed all the steps and everything seems fine, but is there a way I can actually test this to see if the page loads correctly? I want to make sure the page works fine online before it *really* is necessary.
 

system-error

Member
Dec 16, 2014
21
1
3
cPanel Access Level
Root Administrator
OK, I was trying to create an Error 508, which only happens in specific situationa. Instead I made a 404 page and I can test that by just entering an incorrect directory. :) So I solved howe to test it.

But, I now have another issue... I am embedding an image into the .shtml or .html but the images are not showing... The paths appear incorrect. For example, if I visit domain.com/xxxx.html, the page loads fine but images within xxxx.html that are in /images/ are instead pointing to the domain.com/images/ directory.....

So how can I make the customerror/images/ dir deliver the images?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
But, I now have another issue... I am embedding an image into the .shtml or .html but the images are not showing... The paths appear incorrect. For example, if I visit domain.com/xxxx.html, the page loads fine but images within xxxx.html that are in /images/ are instead pointing to the domain.com/images/ directory.....
You will have to use the full path to the image in your script instead of the soft path (e.g. /home/$username/public_html/images/file.jpg instead of images/file.jpg).

Thank you.