apache - Rewrite rules cause infinite redirect loop -


my folder structure looks this:

/var/www/.htaccess /var/www/site/index.php /var/www/site/images/test.png 

where .htaccess file looks this:

rewriteengine on rewritecond /site/%{request_filename} -f rewriterule ^(.*)$ /site/%{request_filename} [l] rewriterule ^(.*)$ /site/index.php [l,qsa] 

essentially, want rewrite urls /site/ directory, , have existing files rewrite paths in site folder, while making file not exist rewrite /site/index.php instead.

the .htaccess file above works /images/test.png, / causes infinite loop, reported in apache error log:

[sat jun 13 21:42:04.003016 2015] [core:error] [pid 12949] [client 127.0.0.1:50560] ah00124: request exceeded limit of 10 internal redirects due probable configuration error. use 'limitinternalrecursion' increase limit if necessary. use 'loglevel debug' backtrace. [sat jun 13 21:42:04.003020 2015] [core:debug] [pid 12949] core.c(3533): [client 127.0.0.1:50560] ah00121: r->uri = /site/index.php [sat jun 13 21:42:04.003022 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] ah00122: redirected r->uri = /site/index.php [sat jun 13 21:42:04.003033 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] ah00122: redirected r->uri = /site/index.php [sat jun 13 21:42:04.003035 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] ah00122: redirected r->uri = /site/index.php [sat jun 13 21:42:04.003037 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] ah00122: redirected r->uri = /site/index.php [sat jun 13 21:42:04.003038 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] ah00122: redirected r->uri = /site/index.php [sat jun 13 21:42:04.003040 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] ah00122: redirected r->uri = /site/index.php [sat jun 13 21:42:04.003041 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] ah00122: redirected r->uri = /site/index.php [sat jun 13 21:42:04.003048 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] ah00122: redirected r->uri = /site/index.php [sat jun 13 21:42:04.003049 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] ah00122: redirected r->uri = /site/index.php [sat jun 13 21:42:04.003050 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] ah00122: redirected r->uri = / 

according documentation, rewrite rules run again if they're in .htaccess files various reasons, i'm not sure why, or how protect against it. tried adding rewritecond before second rewriterule run rule if filename isn't /site/index.php, causes urls (even existing files) rewrite /site/index.php.

to more clear on want, want following uris rewritten following paths:

  • / --> /site/index.php
  • /test -- > /site/index.php
  • /images/test.png --> /site/images/test.png (because file exists)
  • /images/bla.png --> /site/index.php (because file not exist)

the first rewriterule never used because of rewritecond. false. %{request_filename} return full path on server, no filename.

the second rule alone makes infinite loop redirecting /site/index.php itself.

if explain want, try youto make working htaccess

update

rewriteengine on  # if file exist add /site/ rewritecond %{document_root}/site/%{request_uri} -f rewriterule ^(.+)$ /site/$1 [l]  # if no /site/ in request rewrite index.php rewritecond %{request_uri} !^/site/ rewriterule ^ /site/index.php [l] 

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 -