Forum Moderators: phranque
Here's the particulars
httpd.conf:
DocumentError ErrorCode /errors/ErrorCode.php
htaccess in documentroot:
RewriteEngine On
RewriteRule ^(403\.php¦robots\.txt)$ - [L]
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.1
#RewriteRule .* - [F,L]
RewriteRule!^403\.php$ - [F,L]
However, I don't understand why I'm in a loop, and why Apache is displaying its internal error message instead of my custom one
Forbidden
You don't have permission to access /home.php on this server.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Any pointers/help would be *much* appreciated.
P.S. Why do three consecutive x's convert to #*$! on his forum?
-Al
DocumentError ErrorCode /errors/ErrorCode.php and that the actual httpd.conf line for a 403 reads:
ErrorDocument 403 /errors/403.php Note that it must read "ErrorDocument" and not "DocumentError"
If that is the case, the following code is both redundant and incorrect. It should be either
RewriteEngine on
RewriteBase /
#
# Deny access to 127.0.0.1, except for custom 403 error page
RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.1
RewriteRule !^errors/403\.php$ - [F]
RewriteEngine on
RewriteBase /
#
# Exit mod_rewrite if request for custom 403 error page or robots.txt
RewriteRule ^(errors/403\.php¦robots\.txt)$ - [L]
#
# Else deny access to 127.0.0.1
RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.1
RewriteRule .* - [F]
As to why you were looping, the reason is that the access exceptions in your code did not contain the same URL-path as defined for the custom 403 error page: The "error/" path-part was missing. Therefore, the request for the actual custom 403 error page was also being denied, so you got a loop.
Replace the broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters. Posts on this forum are also filtered for character sequences which indicate objectionable words or domain names; You can use "***", "xyz", or "nnn" to indicate 'obscured' characters.
Jim
You are correct in that I was using psuedo-code for the DocummentError line in httpd.conf, and that I got the command backwards. That'll teach me to be literal when I give a code example. :-)
It seems I was tripping over
RewriteRule!^errors/403\.php$ - [F]
-Al
You could have left off the leading ^ to match any file named 403.php or robots.txt located in any folder.
There are always multiple ways to get the job done, but some may have flaws or unintended consequences.