Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

SOLVED Why is Alias needed in ErrorDocument directive?

Discussion in 'General Discussion' started by ItsMattSon, Mar 25, 2018.

  1. ItsMattSon

    ItsMattSon Well-Known Member

    Joined:
    Sep 5, 2016
    Messages:
    167
    Likes Received:
    34
    Trophy Points:
    103
    Location:
    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
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,389
    Likes Received:
    1,857
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. ItsMattSon

    ItsMattSon Well-Known Member

    Joined:
    Sep 5, 2016
    Messages:
    167
    Likes Received:
    34
    Trophy Points:
    103
    Location:
    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
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,389
    Likes Received:
    1,857
    Trophy Points:
    363
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    ItsMattSon likes this.
  5. ItsMattSon

    ItsMattSon Well-Known Member

    Joined:
    Sep 5, 2016
    Messages:
    167
    Likes Received:
    34
    Trophy Points:
    103
    Location:
    Perth
    cPanel Access Level:
    Root Administrator
    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)
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,389
    Likes Received:
    1,857
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    ItsMattSon likes this.
  7. ItsMattSon

    ItsMattSon Well-Known Member

    Joined:
    Sep 5, 2016
    Messages:
    167
    Likes Received:
    34
    Trophy Points:
    103
    Location:
    Perth
    cPanel Access Level:
    Root Administrator
    Ahh, brilliant explanation. Thanks @cPanelMichael. The world makes sense again!
     
    cPanelMichael likes this.
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice