Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

Here is the log file

[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

Thanks.

Hi all,

I have found the solution for my problem.

RewriteCond %{HTTP_REFERER} ^http://example.com/test/store.do [NC] RewriteRule ^/test - [R,L] #prevent for any URL to be place under /test.Thus , prevent looping. RewriteCond %{HTTP_REFERER} ^http://example.com/test/store.do [NC] RewriteRule ^/(.*)$ /test/$1 [R,L]

Thanks everyone.

share|improve this question
    
Why are you using {HTTP_REFERER}? This is not the variable for the request. –  closetnoc May 16 at 3:42
    
because i need to specify only from this url condition , only can met the rule. Because i doing reverse proxy , so if i use the hostname , it will affect all. –  ku1918 May 16 at 3:49
    
I am not sure I understood what you said (I may be too tired), but I think I would be using {REQUEST_URI} or {REQUEST_FILENAME}. –  closetnoc May 16 at 3:58
    
for rewriteCond? how can i modify it? –  ku1918 May 16 at 4:05
1  
ya....it just a test server. But i doing reverse proxy , so it will be like example.com/test. Then it will jump to example.com/test/store.do. –  ku1918 May 16 at 4:25

2 Answers 2

It has been nearly 12 years since I have done any proxy work so I am at a disadvantage. At one point proxies were something I knew cold and configured daily, but tonight, I am just not getting my head around this. As well, I am very adept at doing extremely weird things using .htaccess but not so much for the normal stuff that people do. However, I do see some errors that I will address and throw in some other thoughts that might help.

I invite people to jump in and correct anything I may have made a mistake on. Please.

Your rule creates a loop. Your RewriteRule created the exact condition that the RewriteCond is designed to trap. Each time a rewrite is made, in effect, the entire validation process is started over only to be trapped again and so on. You need an out.

As well, you are using the $1 variable without filling the variable using () in the RewriteCond. If you were trying to fill this in the RewriteRule, then you are appending the original request to /test/ which I do not think you want.

Just addressing these few things...

RewriteCond %{HTTP_REFERER} !^http://example\.com/test/$ [NC]
RewriteCond %{HTTP_REFERER} ^http://example\.com/test/store\.do$ [NC]
RewriteRule .* /test/ [R,L]

The first line is your out. It basically says, if I see the condition I just created, then forget it- all is okay.

I treated this as a standard rewrite, however, while I use HTTP_REFERER for about 60% of my work, I am not sure it applies here. You may be the best judge. Referrer is not the request. It is the from location and not the to location. In other words, it is the page the person has left and not the page the person is going to. Here is another option to try.

RewriteCond %{REQUEST_URI} !^/test/$ [NC]
RewriteCond %{REQUEST_URI} ^/test/store\.do$ [NC]
RewriteRule .* /test/ [R,L]

I mentioned {REQUEST_FILENAME} in my comments, but I am not sure this is what you want, but on the off chance you want to experiment, it refers to the store.do. You may also noticed that I book-ended the regular expressions with both ^ and $. While this is not always necessary, it is generally safer to do.

Let me know if I was able to help. I can always take another SWAG at it.

share|improve this answer
    
still getting same error.you can see my log file i updated. –  ku1918 May 19 at 2:21
    
I am seeing some things that confuse me. You still have applying pattern '(.)$'* and whatshot_v3/hahah/store.do. As well, this well into the loop so it is a bit hard to tell what's going on. I also see that you are using %{HTTP_REFERER} which confuses me. I will have to think on this for a bit. –  closetnoc May 19 at 2:52
    
@w3d I am not sure if you will see this... but if you can understand this question, I differ to your expertise. Can you make sense of this? Please let me know. –  closetnoc May 19 at 2:54

I am doing reverse proxy, so when a user enters example.com/test. I want it to jump to example.com/test/store.do.

If this is your problem, then your rewrite rule should be very simple:

RewriteRule /test/?$ /test/store.do [R]

You really shouldn't be using the referrer in you rewrite rule unless you want to block change what people see based on where they came from. For example, show an error message when people come from some a specific other website.

Here are the reasons that your rewrite rule was failing:

  • You were saying: "If somebody come from /test/store.do, add an extra /test to the beginning of their current page and redirect.
  • The browser would add the extra test and redirect, but redirects don't change the referrer. It would send the same referrer again, which would trigger the same rule.
  • You would keep adding /test and redirecting until you get too many redirects.

I'm not sure exactly how being behind a reverse proxy is figuring in to your problem. You should have two sets of URLs. One that is user visible, and one that is backend only. Something like:

  • Front end: http://example.com/test/store.do
  • Back end: http://127.0.0.1:8080/commercepackage/2012/store.do

You don't say which of these hosts is having the rewrite rule on it. If it is on the back end, your rewrite rules should use the path on the backend (/commercepackage/2012), not the path the users see (/test).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.