shahrahulb
asked on
looping of apache redirect
my rewrite rules
# If this global file exists, we're offline.
RewriteCond /v/xyz.com/asg/offline/off line..html -f
RewriteRule .* /v/xyz.com/asg/offline/off line.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.....
# If this global file exists, we're offline.
RewriteCond /v/xyz.com/asg/offline/off
RewriteRule .* /v/xyz.com/asg/offline/off
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.....
ASKER
in short i don't want to redirect my directory /l/apache/cgi-bin/applicat ion
as i write my cgi application which i want throw to customer so that i can collect user information
Rahul
as i write my cgi application which i want throw to customer so that i can collect user information
Rahul
ASKER
there was a typo in first part...instead of www.abc.ccom it should be www.xyz.com
ASKER
RewriteRule .* /v/xyz.com/asg/offline/off line.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
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/off line\.html -f
RewriteRule !offline\.html$|cgi-bin /v/xyz.com/asg/offline/off line.html [L]
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/off
RewriteRule !offline\.html$|cgi-bin /v/xyz.com/asg/offline/off
the last line must be
RewriteRule !offline\.html$|!cgi-bin /v/xyz.com/asg/offline/off line.html [L]
RewriteRule !offline\.html$|!cgi-bin /v/xyz.com/asg/offline/off
ASKER
can u please explain me what this means !offline\.html$|!cgi-bin
ASKER
i still want to confirm my requirement:
the existing rule:
RewriteCond /v/xyz.com/asg/offline/off line..html -f
RewriteRule .* /v/xyz.com/asg/offline/off line.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
the existing rule:
RewriteCond /v/xyz.com/asg/offline/off
RewriteRule .* /v/xyz.com/asg/offline/off
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
ASKER
also complete path for my cgi file is in /l/apache/cgi-bin/rahul.cg i
>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.cg i
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
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.cg
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
ASKER
do i need both !offline\.html$|!cgi-bin or just !cgi-bin
as my offline.html page itself contains redirect to my 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.
ASKER
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>";
}
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>";
}
ASKER
i have placed rules in :
offline.merchantaccount.co nf
offline.merchantaccount.co
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?
Can you access www.abc.com/cgi-bin/rahul.cgi directly through your browser if offline.html exsists an the rewriterules are in place?
ASKER
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
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
ASKER
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]
RewriteRule !www.abc.com/cgi-bin/rahul.cgi /v/blah...../offline.html [L]
ASKER
hi caterham_www
only !cgi-bin worked :-)
now only more issue
only !cgi-bin worked :-)
now only more issue
ASKER
actually www.abc.com/cgi-bin/rahul.cgi has a submit which redirects to www.abc.com/cgi-bin/test.cgi
i
i
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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></inpu t>";
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.....
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></inpu
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.....
ASKER
hehe
i found the solution
i have to add:
RewriteCond %{REDIRECT_URL} !^/cgi-bin
i found the solution
i have to add:
RewriteCond %{REDIRECT_URL} !^/cgi-bin
ASKER
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??
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.
>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.
ASKER