Forum Moderators: phranque

Message Too Old, No Replies

Problem with redirect

         

michal317

12:10 am on Apr 29, 2006 (gmt 0)

10+ Year Member



Hello!

I've entered a redirect code into the .htaccess according to one's IP:

RewriteCond %{REMOTE_ADDR} ^80\.178\.57\.190$
RewriteRule .* /index.HTML

It worked, but today I started to get this error:

Bad Request
Your browser sent a request that this server could not understand.

Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.

Would anyone know what could be the cause?

Thanks!

jdMorgan

3:48 am on Apr 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the declared name of your ErrorDocument for handling 400-Bad Request? Actually, you'll need to exclude all custom errordocuments from being rewritten, so you might want to list them all.

The 400 Bad Request was likely caused by a nuisance or malicious attacker -- a badly-coded script sent a bad request to your server.

But your code, as written, will rewrite *anything* to /index.HTML, including requests for /index.HTML itself, so you've set yourself up for an 'infinite' rewrite loop here.

An example fix would be:


RewriteCond %{REQUEST_URI} !^/index\.HTML
RewriteCond %{REQUEST_URI} !^/path_to_custom_400_error_page
RewriteCond %{REQUEST_URI} !^/path_to_custom_401_error_page
RewriteCond %{REQUEST_URI} !^/path_to_custom_403_error_page
RewriteCond %{REQUEST_URI} !^/path_to_custom_404_error_page
RewriteCond %{REQUEST_URI} !^/path_to_custom_410_error_page
RewriteCond %{REQUEST_URI} !^/path_to_custom_500_error_page
RewriteCond %{REQUEST_URI} !^/path_to_custom_503_error_page
RewriteCond %{REMOTE_ADDR} ^80\.178\.57\.190$
RewriteRule .* /index.HTML [L]

You can make this more efficient using any of several techniques, but this illustrates and fixes the problem.

Jim