Mod_Rewrite Error code: ERR_TOO_MANY_REDIRECTS

7,157

If possible, the best solution is probably to change the references to the other resources to include the /test/ instead of hacking around it in mod_rewrite.

But, this should work:

RewriteCond %{HTTP_REFERER} ^http://example\.com/test/store\.do [NC]
RewriteRule ^/test - [L]
RewriteCond %{HTTP_REFERER} ^http://example\.com/test/store\.do [NC]
RewriteRule ^/(.*)$ /test/$1 [L]

Note that it's not redirecting since there's no reason to cause the client to send an extra request for each one of the resources, though that should still work.

Share:
7,157

Related videos on Youtube

ku1918
Author by

ku1918

Updated on September 18, 2022

Comments

  • ku1918
    ku1918 almost 2 years

    I know alot people have post about this error , however i still unable to solve it.So that is the reason why i start a new post with it.

    As stated in the title , i encounter a redirect loop when accessing my pages in the website.

    Here is my rewrite config.

    RewriteCond %{HTTP_REFERER} ^http://example\.com/test/store\.do [NC]
    RewriteRule (.*)$ /test/$1 [R]
    

    So , how do I solve this redirect error?

    [Fri May 16 12:18:20.345204 2014] [rewrite:trace3] [pid 29462:tid 1193511232] mod_rewrite.c(475): [client 172.16.28.96:60187] 172.16.28.96 - - [example.com/sid#1e84d1c0][rid#1e954910/initial] applying pattern '(.*)$' to uri '/test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test/ /store.do', referer: http://example.com/test/store.do
    [Fri May 16 12:18:20.345213 2014] [rewrite:trace4] [pid 29462:tid 1193511232] mod_rewrite.c(475): [client 172.16.28.96:60187] 172.16.28.96 - - [example.com/sid#1e84d1c0][rid#1e954910/initial] RewriteCond: input='http://example.com/test/store.do' pattern='^http://example\\.com/test/store\\.do' [NC] => matched, referer: http://example.com/test/store.do
    [Fri May 16 12:18:20.345218 2014] [rewrite:trace2] [pid 29462:tid 1193511232] mod_rewrite.c(475): [client 172.16.28.96:60187] 172.16.28.96 - - [example.com/sid#1e84d1c0][rid#1e954910/initial] rewrite '/test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//whatshot_v3/hahah/store.do' -> '/test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//store.do', referer: http://example.com/test/store.do
    [Fri May 16 12:18:20.345233 2014] [rewrite:trace2] [pid 29462:tid 1193511232] mod_rewrite.c(475): [client 172.16.28.96:60187] 172.16.28.96 - - [example.com/sid#1e84d1c0][rid#1e954910/initial] explicitly forcing redirect with http://example.com/test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test/ /store.do, referer: http://example.com/test/store.do
    [Fri May 16 12:18:20.345239 2014] [rewrite:trace1] [pid 29462:tid 1193511232] mod_rewrite.c(475): [client 172.16.28.96:60187] 172.16.28.96 - - [example.com/sid#1e84d1c0][rid#1e954910/initial] escaping http://example.com/test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//store.do for redirect, referer: http://example.com/test/store.do
    [Fri May 16 12:18:20.345245 2014] [rewrite:trace1] [pid 29462:tid 1193511232] mod_rewrite.c(475): [client 172.16.28.96:60187] 172.16.28.96 - - [example.com/sid#1e84d1c0][rid#1e954910/initial] redirect to http://example.com/test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//test//store/store.do [REDIRECT/302], referer: http://example.com/test/store.do
    

    Here is my log file.

    Thanks.

    • ravi yarlagadda
      ravi yarlagadda about 10 years
      What are you trying to accomplish with the redirect that you have configured?
    • ku1918
      ku1918 about 10 years
      Well , I am doing reverse proxy. So i have a webpage like example.com/test/store.do by using proxypass. However , when i access any pages in that website , it will go to example.com/store/store.do. What i am trying to do here is to add the /test path for all the pages in that website.Or else i will get 404 error.
    • ravi yarlagadda
      ravi yarlagadda about 10 years
      So, that RewriteRule is intended to proxy? Is that correct?
    • ku1918
      ku1918 about 10 years
      yup. Its for proxy.
    • ravi yarlagadda
      ravi yarlagadda about 10 years
      There's no remote host in that rule - what are you trying to proxy to?
    • ku1918
      ku1918 about 10 years
      I use proxypass for proxy..Not using mod_rewrite for proxy.
    • ravi yarlagadda
      ravi yarlagadda about 10 years
      Ok, then we're back to "What are you trying to accomplish with the redirect that you have configured?"
    • ku1918
      ku1918 about 10 years
      First i use passproxy to RP to my website on another server.So like the example i given , i type example.com/test will lead to example.com/test/store.do. Now in that website has alot of pages , the problem is that everything(images,css,links) must from example.com/test/.However , the problem is that all the subpages are coming from example.com/ . thus causes 404 error. The rewriterule for this whole thing is to add to /test path infront of all the subpages. For an example , example.com/test/smth.do. Without the /test path , it will lead 404 error.
    • ku1918
      ku1918 about 10 years
      Thus , i try my rewriterule that i have shown , it create a loop (20times) , thus creating the err_too_many_redirects.
  • ku1918
    ku1918 about 10 years
    Yeah..i did that...just keep saying redirect 302 ..then all the loop path.
  • Jason Floyd
    Jason Floyd about 10 years
    You should be able to see what rewrite rule is matching and what its rewriting it to that is causing the looping in the logs.
  • ku1918
    ku1918 about 10 years
    still the same..still have the loop. this is the log. prefixed with document_root to /usr/local/apache2/htdocs go-ahead with /usr/local/apache2/htdocs/ got this log now.
  • ku1918
    ku1918 about 10 years
    ok...i added the R flag, now it working already. Thanks alot. But can you explain RewriteRule ^/test - [L] . what this means?
  • ravi yarlagadda
    ravi yarlagadda about 10 years
    @ku1918 It's making the following rule (which was causing the loop when applied to URLs under /test) not apply to URLs under /test.