Jump to content

ErrorDocument 403 Does Not Work


Recommended Posts

Hi All,

In an .htaccess file, I am trying to implement a 404 and a 403 ErrorDocument directives, like this :

ErrorDocument 403 /path/403.html
ErrorDocument 404 /path/404.html

While the 404 directive works correctly by displaying the content of the 404.html file, the 403 one still leads to the display of the generic "403 Forbidden You don't have permission to access....".

Did I miss something?



Link to comment
Share on other sites

1 hour ago, requinix said:

Have you granted access to the 403.html page?

I made nothing special to neither grant nor deny access. Since 404.html page is accessible (its contents shows), and it is in the same folder as 403.html, I guess that 403.html should be accessible too. Am I wrong?

Link to comment
Share on other sites

The 403 in the first one is because you're requesting a directory, it doesn't have a DirectoryIndex file, and you told Apache not to list directory contents. Thus a 403. So either add a DirectoryIndex, allow Apache to list directory contents, or live with the 403 and don't link people to it.

The lack of CSS in the second one is because you're using relative URLs for your CSS files when you should be absolute URLs. Absolute ones start with a slash and will work from anywhere on your site, relative ones don't and won't.

But back to the original question. What happens if you go to /path/403.html yourself in the browser?

Link to comment
Share on other sites

Entering myself /path/403.html  loads the 403.html file and displays its contents.

I was wrong in saying that the CSS gets lost. It is not the CSS (in fact it is inline CSS) but the JS code, which does some formatting and is stored in a separate JS file. Sorry about that, but I guess what you said is also valid for JS too.


Link to comment
Share on other sites

Well, now, using absolute URLs for the external js file, both custom pages display correctly.

There is another point  : Does the fact of using absolute URLs for css & js requires also the use of absolute URLs for the "action" attribute in HTML forms ? The page contains a form and it seemed to me that leaving a relative URL in the "action" attribute would lead to the reload of the page instead of loading the page pointed by the action attribute.

Link to comment
Share on other sites

It depends where the page is and where the thing you want to reference is.

An absolute URL (meaning it starts with a slash, not that it has the full scheme and hostname in it) will work everywhere. A relative URL (no leading slash) means it is relative to the current "directory" of the page.

Right now I'm looking at /topic/307719-errordocument-403-does-not-work/?tab=comments#comment-1561188. The "directory" would be /topic/307719-errordocument-403-does-not-work/ (note there was a trailing slash) so a relative URL of "foo" will go to /topic/307719-errordocument-403-does-not-work/foo. If that's what I want then okay. But if I want /foo then I have to actually write "/foo". The other option is "../../foo" but that's stupid so don't do it.

Want the page to submit back to itself? Then a relative URL is fine. Or leave the action blank. But an absolute URL wouldn't be harmful.

  • Thanks 1
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.