0

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.

3 Answers 3

1

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]
</Directory>
2
  • 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, 2014 at 7:31
  • 1
    I have edited the answer. Just give it a try. Jul 4, 2014 at 16:00
0

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
</Files>

ErrorDocument   403     /err403.php
1
0

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
        </Directory>
     </VirtualHost>

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .