I am trying to set up an 403 error document in Apache, using a PHP file, like this (via .htaccess):

order deny,allow
deny from all
allow from [MY_IP]
ErrorDocument 403 /err403.php

but it doesn't works, it shows the apache default 403 error, but if I use a .html errordocument it works, like this:

order deny,allow
deny from all
allow from [MY_IP]
ErrorDocument 403 /err403.html

Then it shows the customized HTML document with the error page. I am using SuPHP. And the apache and php in Ubuntu 14.04 Server repositories.

If I remove this restriction from the .htaccess, the file err403.php could be read normally.

Any ideas?? Thanks!!

edit: ie., changing the allow from ip to another ip so that it triggers the error.


You need to place the err403.php in a directory where the user (or in your case the IP) has access to.

Otherwise apache can't deliver that page and defaults back tho the standard 403 error page.

Also make sure (as you use ubuntu 14.04 with apache 2.4) that you change your access config using "require". The order,allow,denied directives are deprecated.

Complete example:

ErrorDocument 403 /path/accessible/to/all/err403.php

<Directory /path/your/website/>
    Require ip [your_ip]
  • No... it works with the .html file, and it is in the same directory, with the same permissions. And I have another hosting that this works with php but I don't have root access there, and I don't have any idea on which configuration I should change for it to work. – Iacchus Jul 4 '14 at 7:31
  • 1
    I have edited the answer. Just give it a try. – rechengehirn Jul 4 '14 at 16:00

In addition to reply by rechengehirn one can put the file in the own restricted folder, allowing only the error file.

order deny,allow
deny from all
allow from [MY_IP]

<Files "err403.php">
    allow from all

ErrorDocument   403     /err403.php

I struggled with this for a long time today, and nothing worked until I used a FQDN:

    <VirtualHost *:80>
        ServerName myServer.rad.awesome.com
        ServerAlias myServer.rad
        Alias /static/ /my/Doc/Root
        <Directory /my/Doc/Root/static>
            Options All
            AllowOverride All
            ErrorDocument 403 "http://myServer.rad.awesome.com/youNoEnter.html"
            order deny,allow
            Deny from all
            allow from (MY IP)
            satisfy any

Just place your ErrorDocument in an absolute URL and that might do the trick.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.