looping of apache redirect

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.....
LVL 1
shahrahulbAsked:
Who is Participating?
 
caterham_wwwConnect With a Mentor Commented:
> 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
 
shahrahulbAuthor Commented:
its kind of looping
0
 
shahrahulbAuthor Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
shahrahulbAuthor Commented:
there was a typo in first part...instead of www.abc.ccom  it should be www.xyz.com
0
 
shahrahulbAuthor Commented:
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
 
caterham_wwwCommented:
>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
 
caterham_wwwCommented:
the last line must be
RewriteRule !offline\.html$|!cgi-bin /v/xyz.com/asg/offline/offline.html [L]
0
 
shahrahulbAuthor Commented:
can u please explain me what this means    !offline\.html$|!cgi-bin
0
 
shahrahulbAuthor Commented:
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
 
shahrahulbAuthor Commented:
also complete path for my cgi file is in /l/apache/cgi-bin/rahul.cgi
0
 
caterham_wwwCommented:
>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
 
shahrahulbAuthor Commented:
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
 
caterham_wwwCommented:
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
 
shahrahulbAuthor Commented:
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
 
shahrahulbAuthor Commented:
i have placed rules in :
offline.merchantaccount.conf

0
 
caterham_wwwCommented:
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
 
shahrahulbAuthor Commented:
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
 
shahrahulbAuthor Commented:
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
 
shahrahulbAuthor Commented:
hi caterham_www

only !cgi-bin   worked   :-)

now only more issue
0
 
shahrahulbAuthor Commented:
actually www.abc.com/cgi-bin/rahul.cgi  has a submit which redirects to www.abc.com/cgi-bin/test.cgi

i
0
 
shahrahulbAuthor Commented:
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
 
shahrahulbAuthor Commented:
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
 
shahrahulbAuthor Commented:
hehe

i found the solution

i have to add:

RewriteCond %{REDIRECT_URL} !^/cgi-bin
0
 
shahrahulbAuthor Commented:
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
 
caterham_wwwCommented:
> 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.