[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

looping of apache redirect

Posted on 2005-04-07
25
Medium Priority
?
285 Views
Last Modified: 2010-08-05
my rewrite rules

# If this global file exists, we're offline.
RewriteCond /v/xyz.com/asg/offline/offline..html -f
RewriteRule .* /v/xyz.com/asg/offline/offline.html [L]

which means as soon as it finds the offline.htm page in /v/xyz.com/asg/offline it throws my outofservice page. (which is offline.html)
so all the trafic coming from www.abc.com gets redirected to offline.html page which says the site is temporarily down.

but i have something like www.xyz.com/cgi-bin/print    i want this site to be live....but due to my rewrite rule it throws offline.html page as this url is coming from www.xyz.com

can i write some condition which says www.xyz.com/cgi-bin/print should not be redirected....i guess there should be some condition.....
0
Comment
Question by:shahrahulb
  • 18
  • 7
25 Comments
 
LVL 1

Author Comment

by:shahrahulb
ID: 13731683
its kind of looping
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13731706
in short i don't want to redirect my directory /l/apache/cgi-bin/application

as i write my cgi application which i want throw to customer so that i can collect user information

Rahul  
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13736497
there was a typo in first part...instead of www.abc.ccom  it should be www.xyz.com
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:shahrahulb
ID: 13737199
RewriteRule .* /v/xyz.com/asg/offline/offline.html [L]
means everything is redirected to offline.html


can i add some exclude condition , that don't redirect
/l/apache/cgi-bin/ directory to offline.html

just to prevent my looping issue
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 13737409
>but due to my rewrite rule it throws offline.html page as this url is coming from www.xyz.com
Where did you place the rules?

this will prevent looping and apply only for abc.com:
# If this global file exists, we're offline.
RewriteCond %{HTTP_HOST} ^(www\.)?abc\.com
RewriteCond /v/xyz.com/asg/offline/offline\.html -f
RewriteRule !offline\.html$|cgi-bin /v/xyz.com/asg/offline/offline.html [L]
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 13737415
the last line must be
RewriteRule !offline\.html$|!cgi-bin /v/xyz.com/asg/offline/offline.html [L]
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13737483
can u please explain me what this means    !offline\.html$|!cgi-bin
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13737527
i still want to confirm my requirement:

the existing rule:
RewriteCond /v/xyz.com/asg/offline/offline..html -f
RewriteRule .* /v/xyz.com/asg/offline/offline.html [L]

this redirects everything from www.abc.com/....... to offline.html page.

the contents of my offline.html page is
<META HTTP-EQUIV="Refresh"   CONTENT="5; URL=www.abc.com/cgi-bin/rahul.cgi">

so what is happening is even this gets redirect to offline.html since it is starting wth www.abc.com

i want to prevent this looping scenario
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13737539
also complete path for my cgi file is in /l/apache/cgi-bin/rahul.cgi
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 13737601
>can u please explain me what this means    !offline\.html$|!cgi-bin

filepath contains not offilne.html at the end or filepath contains not cgi-bin

> also complete path for my cgi file is in /l/apache/cgi-bin/rahul.cgi
The complete path is not seen by the pattern of the rewrite rule, it just sees the filepath, i.e. in httpd.conf /cgi-bin/rahul.cgi, in /.htaccess without the leading slash cgi-bin/rahul.cgi
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13737707
do i need both !offline\.html$|!cgi-bin  or just !cgi-bin

as my offline.html page itself contains redirect to my cgi-bin
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 13737803
where did you place the rules? It depends on that. If you placed the rules in per-dir context (.htaccess, inside <Directory> or <Location> of httpd.conf, you'll need this to prevent looping.
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13737820
i tried both

as soon as as it sees the offline.html file in /v/xyz.com/asg/offline/    it throws offline.html also my offline.html gets redirected to www.abc.com/cgi-bin/rahul.cgi 
which i can see in the browser.
but i get the error:

Method Not Allowed
The requested method POST is not allowed for the URL /cgi-bin/rahulenv.cgi.


when i remove offline.html from /v/xyz.com/asg/offline/  and manually try www.abc.com/cgi-bin/rahul.cgi   it works fine

contents of rahul.cgi is:
#!/usr/local/bin/perl
##  printenv -- demo CGI program which just prints its environment

print "Content-type: text/plain\n\n";
foreach $var (sort(keys(%ENV))) {
    $val = $ENV{$var};
    $val =~ s|\n|\\n|g;
    $val =~ s|"|\\"|g;
    print "${var}=\"${val}\"\n<br>";
}



0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13737891
i have placed rules in :
offline.merchantaccount.conf

0
 
LVL 27

Expert Comment

by:caterham_www
ID: 13737921
Check your browser headers i.e. with LiveHTTP-Headers for firefox, it looks like your browser is sending a POST-Request on <META HTTP-EQUIV="Refresh"   CONTENT="5; URL=www.abc.com/cgi-bin/rahul.cgi">.

Can you access www.abc.com/cgi-bin/rahul.cgi directly through your browser if offline.html exsists an the rewriterules are in place?
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13737984
my modified rewrite rule
RewriteRule !offline\.html$|!cgi-bin /v/blah...../offline.html [L]

also the offline.htm exists in the directory....

i cannot access the www.abc.com/cgi-bin/rahul.cgi

same error i m getting from both mozilla and IE


as soon as i remove offline.html page   ---------- then no errror and the cgi works fine
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13738021
may be can i specify complete url in rule (just guessing never done before)

RewriteRule !www.abc.com/cgi-bin/rahul.cgi /v/blah...../offline.html [L]
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13738166
hi caterham_www

only !cgi-bin   worked   :-)

now only more issue
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13738187
actually www.abc.com/cgi-bin/rahul.cgi  has a submit which redirects to www.abc.com/cgi-bin/test.cgi

i
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13738198
oops!!! forgot

even test.cgi is is in same directory cgi-bin  so i assume that won't be redirected.....

let me try and will tell u
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 2000 total points
ID: 13738366
> may be can i specify complete url in rule (just guessing never done before)
>RewriteRule !www.abc.com/cgi-bin/rahul.cgi /v/blah...../offline.html [L]

no, the domain is not seen here


>even test.cgi is is in same directory cgi-bin  so i assume that won't be redirected.....
right.

I don't know why this did not work in this case, because it works on my windows testing envrionment.

But we can try other ways:

RewriteEngine On
RewriteCond /v/xyz.com/asg/offline/offline\.html -f
RewriteCond %{REQUEST_URI} !offline\.html
RewriteCond %{REQUEST_URI} !^/cgi-bin
RewriteRule ^.* /v/xyz.com/asg/offline/offline.html [L]
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13738645
here is the last isseu


in my offline.html i m redirecting it to www.abc.com/cgi-bin/rahul.cgi

as i told u earlier rahul.cgi has a button...print "<html> <form action=http://abc.com/cgi-bin/customers.cgi> <input type=submit value=submit></form></input>";

the issue is when i click the button, its looping now and again goes back to www.abc.com/cgi-bin/rahul.cgi


once i get rid of this issue, i m all set.....
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13739609
hehe

i found the solution

i have to add:

RewriteCond %{REDIRECT_URL} !^/cgi-bin
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13739777
one thing is, even after i remove offline.html file, i have to manually delete the cookies and clear the cache from the browser....otherwise it still keeps on redirecting

why??
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 13740645
> hehe
>i found the solution
>i have to add:
>RewriteCond %{REDIRECT_URL} !^/cgi-bin

There seems to be sthg. wrong with request_uri, this is not normal.

>one thing is, even after i remove offline.html file, i have to manually delete the cookies and clear the cache from the browser....otherwise it still keeps on redirecting
This is a browser issue and a common problem on testing envrionments. The Browser tries to load pages from the local browser cache. The server responds with a 404 but the page is being loaded from the local cache.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month18 days, 2 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question