apache - .htaccess - preventing infinite loops with URL rewriting -


i have .htaccess contains following :

<files .htaccess> order allow,deny deny </files>  options +followsymlinks rewriteengine on rewritecond %{request_uri} !^(.*)/maintenance/(.*)$ [nc]  rewriterule ^(.*).jpg$ /mysite/maintenance/transparent.png [nc,r=302,l] rewriterule ^(.*).jpeg$ /mysite/maintenance/transparent.png [nc,r=302,l] rewriterule ^(.*).gif$ /mysite/maintenance/transparent.png [nc,r=302,l] rewriterule ^(.*).png$ /mysite/maintenance/transparent.png [nc,r=302,l]  rewriterule ^(.*).php$ /mysite/maintenance/maintenance.php [nc,r=302,l] 

tested on localhost.

with these settings, have infinite loop when trying load http://localhost/mysite/test.php, (correctly) redirected http://localhost/mysite/maintenance/maintenance.php

the loop seems due 4 image redirection (note : maintenance page has 1 unique jpg background image located in maintenance folder root). commenting these 4 redirection lines solves problem.

but don't see why enter in infinite loop /maintenance/ path excluded redirection in rewritecond, , why redirection on images can interfere problem.

can ?

you have reorder rewriteconds this:

rewriteengine on  rewriterule \.jpg$ /mysite/maintenance/transparent.png [nc,r=302,l] rewriterule \.jpeg$ /mysite/maintenance/transparent.png [nc,r=302,l] rewriterule \.gif$ /mysite/maintenance/transparent.png [nc,r=302,l] rewritecond %{request_uri} !^.*/maintenance/.*$ [nc] rewriterule \.png$ /mysite/maintenance/transparent.png [nc,r=302,l]  rewritecond %{request_uri} !^.*/maintenance/.*$ [nc] rewriterule \.php$ /mysite/maintenance/maintenance.php [nc,r=302,l] 

rewritecond directive affects first rewriterule after it.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -