Search code examples
apache.htaccessfedorahttp-status-code-403httpforbiddenhandler

Custom 403 Error Page in Root Directory


I'm blocking a few IP addresses using the htaccess technique and this works well for all my pages except for the site/document root where the Fedora Core Test Page is displayed instead.

I'm aware that the test page is shown when no document in the root directory is found, thus I have created multiple documents and set the directory index, where index.php is my regular document root file.

N.B. I don't have access to /etc/httpd/conf.d/welcome.conf

Below is the related htaccess code:

DirectoryIndex index.php index.html 403.php

ErrorDocument 403 /403.php

order allow,deny
deny from 5.39.218
deny from 146.0.74
deny from 5.39.219
deny from 176.102.38
allow from all

<FilesMatch "(403.php|hero.jpg|index.html)$">
 order allow,deny
 allow from all
</FilesMatch>

Is there a way of displaying my custom 403 page for the website root?

Any suggestions would be much appreciated.


Solution

  • People looking for a complete solution:

    • Must Ass FilesMatch "^.*$" line to ip's to block
    • Add ^ to the front of the FilesMatch for the allowed files

    Finished Code:

    DirectoryIndex index.php index.html 403.php
    
    ErrorDocument 403 /403.php
    
    <FilesMatch "^.*$">
      order allow,deny
      allow from all
      deny from 5.39.218
      deny from 146.0.74
      deny from 5.39.219
      deny from 176.102.38
    </FilesMatch>
    
    <FilesMatch "^(|403\.php|hero\.jpg)$">
      order allow,deny
      allow from all
    </FilesMatch>