SOLVED Why is Alias needed in ErrorDocument directive?

ItsMattSon

Well-Known Member
Sep 5, 2016
182
38
103
Perth
cPanel Access Level
Root Administrator
Hi cPanel,

Can you explain why the Alias works, but not when using the actual path?

Works:

Code:
Alias "/htdocscustom" "/usr/local/apache/htdocscustom"
ErrorDocument 400 /htdocscustom/400.shtml
ErrorDocument 401 /htdocscustom/401.shtml
ErrorDocument 403 /htdocscustom/403.shtml
ErrorDocument 404 /htdocscustom/404.shtml
ErrorDocument 500 /htdocscustom/500.shtml
Doesn't work:

Code:
ErrorDocument 400 /usr/local/apache/htdocscustom/400.shtml
ErrorDocument 401 /usr/local/apache/htdocscustom/401.shtml
ErrorDocument 403 /usr/local/apache/htdocscustom/403.shtml
ErrorDocument 404 /usr/local/apache/htdocscustom/404.shtml
ErrorDocument 500 /usr/local/apache/htdocscustom/500.shtml
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hi Matt,

Can you verify where exactly you are setting up those entries at? Is this in a .htaccess file or in an Apache include file?

Thank you.
 

ItsMattSon

Well-Known Member
Sep 5, 2016
182
38
103
Perth
cPanel Access Level
Root Administrator
Hi @cPanelMichael,

Those were put in Service Configuration > Apache Configuration > Include Editor > Pre VirtualHost Include (All Versions).

When the full path didn't work, I tried with the Alias and it worked no problem. I changed it back to see if it was just dumb luck but then it would go back to saying (on a 404 page for example) "Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request". Not sure why :p
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hi Matt,

Apache is configured to first look for a custom error page in the document root of the website (e.g. /home/username/public_html/404.shtml). You noted the use of the following custom entry with the full path:

Code:
ErrorDocument 404 /usr/local/apache/htdocscustom/404.shtml
Thus, as I understand, your custom entry leads to Apache searching for the custom error page at the following location:

/home/username/usr/local/apache/htdocscustom/404.shtml

That location doesn't exist by default so it won't load. By adding the Alias entry, the request goes to the correct location.

Thank you.
 
  • Like
Reactions: ItsMattSon

ItsMattSon

Well-Known Member
Sep 5, 2016
182
38
103
Perth
cPanel Access Level
Root Administrator
Hi Matt,

Apache is configured to first look for a custom error page in the document root of the website (e.g. /home/username/public_html/404.shtml). You noted the use of the following custom entry with the full path:

Code:
ErrorDocument 404 /usr/local/apache/htdocscustom/404.shtml
Thus, as I understand, your custom entry leads to Apache searching for the custom error page at the following location:

/home/username/usr/local/apache/htdocscustom/404.shtml

That location doesn't exist by default so it won't load. By adding the Alias entry, the request goes to the correct location.

Thank you.
Hi @cPanelMichael,

Thanks! Makes sense, but can you confirm it is true since I have the / before the path? (ie. /usr) so shouldn't that start at the root level? (if the / wasn't there, what you said would make perfect sense though)
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hello,

That's the same behavior I see on a test environment, even when using the full path as you described. Apache excepts the path from the document root of the website that's accessed, not the full path to the file on the server. The alias entry works because it's adding that alias entry to all virtual hosts on the server.

Thank you.
 
  • Like
Reactions: ItsMattSon