Forum Moderators: phranque

Message Too Old, No Replies

Custom error page rewrite rule not working

         

bouncybunny

1:21 am on Jan 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am using a bad bot blocking script to show 403 errors, that a very kind member of these forums showed me.

The script work fine as do the 403 errors. But the custom error page is not displayed, just the default one.

Using CPanel, I created a custom error page for 403 errors. This is easy enough. CPanel creates a file in the root folder with the custom error information and calls it whateveriwant.shtml (or whatever).

I was advised to alter the end of my nad bot script rewrite rule from this;

RewriteRule .* - [F]

To something like this;

RewriteRule!^whateveriwant\.shtml$ - [F]

Or have I got that wrong?

Thanks for any help.

bouncybunny

1:38 am on Jan 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, I have noticed one difference.

I am getting this message;

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

Does that mean that the user is also being forbidden to view the error page?

bouncybunny

1:42 am on Jan 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, please ignore me.

It seems that the custom error page needs to be named 403.shtml

As you were...

jdMorgan

2:36 am on Jan 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can name it anything you want, but the rule you posted needs to exclude that name/page from being forbidden.

Otherwise, say a user-agent or IP address is forbidden, and the server attempts to send your custom 403 error page as a response. If that custom 403 error page is not excluded from your rule, then it too will be forbidden, because the requesting user-agent or IP address is still forbidden. So, the server again attempts to send the custom 403 error page in response to this second error, and again gets a 403 error -- and you've got an 'infinite' loop there.

So, your rule should be


RewriteRule !^whatever-your-custom-403-page-is-named\.whatever-type-file-it-is$ - [F]

Jim