Link to home
Start Free TrialLog in
Avatar of shahrahulb
shahrahulb

asked on

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.....
Avatar of shahrahulb
shahrahulb

ASKER

its kind of looping
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  
there was a typo in first part...instead of www.abc.ccom  it should be www.xyz.com
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
>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]
the last line must be
RewriteRule !offline\.html$|!cgi-bin /v/xyz.com/asg/offline/offline.html [L]
can u please explain me what this means    !offline\.html$|!cgi-bin
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
also complete path for my cgi file is in /l/apache/cgi-bin/rahul.cgi
>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
do i need both !offline\.html$|!cgi-bin  or just !cgi-bin

as my offline.html page itself contains redirect to my cgi-bin
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.
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>";
}



i have placed rules in :
offline.merchantaccount.conf

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?
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
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]
hi caterham_www

only !cgi-bin   worked   :-)

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

i
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
ASKER CERTIFIED SOLUTION
Avatar of caterham_www
caterham_www
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.....
hehe

i found the solution

i have to add:

RewriteCond %{REDIRECT_URL} !^/cgi-bin
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??
> 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.