4

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.

daba
  • 157
  • 3
  • 14
  • Related: http://stackoverflow.com/questions/14001228/htaccess-deny-from-all-gets-apache-server-test-page/23562801#23562801 – Maxime Pacary May 09 '14 at 10:59

2 Answers2

2

Try this code:

DirectoryIndex index.php index.html 403.php

ErrorDocument 403 /403.php

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
Satisfy    any

<FilesMatch "^(|403\.php|hero\.jpg)$">
 order allow,deny
 allow from all
</FilesMatch>
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Sadly this made no difference, still getting that pesky Fedora page when browsing the home page from a blocked ip. – daba Nov 17 '13 at 05:18
  • Note that both your version and my original one blocks and displays the error page correctly, it's only on the root directory that trouble sets in. – daba Nov 17 '13 at 05:24
  • So the problem is only not getting custom 403 page? – anubhava Nov 17 '13 at 06:16
  • No, I can get the custom 403 to appear for all requests except for the root directory (where I get the Fedora page). Eg example.com gives me the Fedora page, but example.com/hello/ gives me the custom 403 error. – daba Nov 17 '13 at 07:11
  • Which is expected because you have `allow from all for `index.html`. If you remove `index.html` from `FilesMatch` directive then you'll have 403 custom error for home page also. – anubhava Nov 17 '13 at 07:35
  • I get the Fedora Start Page either way, which is not what I want. I wish regular users to see index.php and blocked users to see 403.php for the home page. – daba Nov 17 '13 at 08:01
  • Great that you got it working, I looked at your answer. You can merge it in same FilesMatch directive as I showed in my edited answer. – anubhava Nov 17 '13 at 09:05
0

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>
daba
  • 157
  • 3
  • 14