You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Andrea Rossignoli <so...@polin.it> on 2003/01/26 15:30:22 UTC

[users@httpd] Redirection

Hi,
the manual gives this example:

http://httpd.apache.org/docs/urlmapping.html#redirect

----
Alternatively, to temporarily redirect all pages on a site to one particular
page, use the following:

RedirectMatch temp .* http://www.example.com/startpage.html
----

If example.com is the same server where that directive is put then it will
create an infinite request loop.
I tried it on my windows pc and I put that directive inside an .htaccess,
the result is an infinite request loop.

In fact when the browser will ask for /startpage.html (because it was
redirected to) the rule .* matches it again.

I'm sure I was wrong,
so please help me to understand.


Thanks,
Andrea, Italy


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Redirection

Posted by Joshua Slive <jo...@slive.ca>.


On Sun, 26 Jan 2003, Andrea Rossignoli wrote:

> Hi,
> the manual gives this example:
>
> http://httpd.apache.org/docs/urlmapping.html#redirect
>
> ----
> Alternatively, to temporarily redirect all pages on a site to one particular
> page, use the following:
>
> RedirectMatch temp .* http://www.example.com/startpage.html
> ----
>
> If example.com is the same server where that directive is put then it will
> create an infinite request loop.

Yes, the example is a little imprecise.  To be clear, it should say "...
one particular page on another site..." and the directive should use
http://othersite.example.com/startpage.html.

> I tried it on my windows pc and I put that directive inside an .htaccess,
> the result is an infinite request loop.
>
> In fact when the browser will ask for /startpage.html (because it was
> redirected to) the rule .* matches it again.

You can do this, but it requires mod_rewrite.  Something like (untested)

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/startpage.html$
RewriteRule .* http://www.example.com/startpage.html

Alternatively, you can always point the DocumentRoot at a directory
containing only startpage.html, turn off Indexes, and use
ErrorDocument 404 http://www.example.com/startpage.html

Come to think of it, it may also be possible in 2.0 to use a fancy PCRE
regex with the RedirectMatch to get it.  But you'll have to find more of a
PCRE expert or dig into the PCRE manual to come up with that.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Redirection

Posted by Joshua Slive <jo...@slive.ca>.


On Sun, 26 Jan 2003, Andrea Rossignoli wrote:

> Hi,
> the manual gives this example:
>
> http://httpd.apache.org/docs/urlmapping.html#redirect
>
> ----
> Alternatively, to temporarily redirect all pages on a site to one particular
> page, use the following:
>
> RedirectMatch temp .* http://www.example.com/startpage.html
> ----
>
> If example.com is the same server where that directive is put then it will
> create an infinite request loop.

Yes, the example is a little imprecise.  To be clear, it should say "...
one particular page on another site..." and the directive should use
http://othersite.example.com/startpage.html.

> I tried it on my windows pc and I put that directive inside an .htaccess,
> the result is an infinite request loop.
>
> In fact when the browser will ask for /startpage.html (because it was
> redirected to) the rule .* matches it again.

You can do this, but it requires mod_rewrite.  Something like (untested)

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/startpage.html$
RewriteRule .* http://www.example.com/startpage.html

Alternatively, you can always point the DocumentRoot at a directory
containing only startpage.html, turn off Indexes, and use
ErrorDocument 404 http://www.example.com/startpage.html

Come to think of it, it may also be possible in 2.0 to use a fancy PCRE
regex with the RedirectMatch to get it.  But you'll have to find more of a
PCRE expert or dig into the PCRE manual to come up with that.

Joshua.

---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org


Re: [users@httpd] Redirection

Posted by Rich Bowen <rb...@rcbowen.com>.
On Sun, 26 Jan 2003, Andrea Rossignoli wrote:

> Hi,
> the manual gives this example:
>
> http://httpd.apache.org/docs/urlmapping.html#redirect
>
> ----
> Alternatively, to temporarily redirect all pages on a site to one particular
> page, use the following:
>
> RedirectMatch temp .* http://www.example.com/startpage.html
> ----
>
> If example.com is the same server where that directive is put then it will
> create an infinite request loop.
> I tried it on my windows pc and I put that directive inside an .htaccess,
> the result is an infinite request loop.

Yes, that is correct. Redirecting a URL to itself is a bad idea.

> In fact when the browser will ask for /startpage.html (because it was
> redirected to) the rule .* matches it again.
>
> I'm sure I was wrong,
> so please help me to understand.

No, you were right. The rule is not intended to be used to redirect back
to the same server, as that will indeed cause a loop.

-- 
Nothing is perfekt. Certainly not me.
Success to failure. Just a matter of degrees.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org