You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Matthew Pearce <mp...@digitas.com> on 2002/04/16 16:16:54 UTC

redirect directive: avoiding recursive loop

I have multiple hosts using the same IP address. How do I get the all valid urls to redirect one host. To understand what I am asking try launching your browser and enter the url http://sun.com. You'll see that the url changes to http://www.sun.com
I have tried to do this in Apache using the Redirect directive in mod_alias.

<VirtualHost *>
    DocumentRoot D:\Apache\htdocs\manual\vhosts
    Redirect permanent   /     http://www.xxx.com/
    ServerName www.xxx.com
</VirtualHost>

The desired behaviour can be seen in examples 1 & 2 below. Unfortunately, my suggested configuration meets the requirement in example 1, but not example 2 because requests for www.xxx.com are redirected to themselves. The user agent cannot detect the infinite recursion.

Example 1:
Requesting the header for http://xxx.com, the user agent is advised to try location http://www.xxx.com

8< --------------------------
HEAD / HTTP/1.1
host: xxx.com

HTTP/1.1 301 Moved Permanently
Date: Tue, 16 Apr 2002 13:59:23 GMT
Server: Apache/1.3.24 (Win32)
Location: http://www.xxx.com
Content-Type: text/html; charset=iso-8859-1
------------------------- >8


Example 2:
Requesting the header for http://www.xxx.com, the user agent receives the OK.

8< --------------------------
HEAD / HTTP/1.1
host: www.xxx.com

HTTP/1.1 200 OK
Date: Tue, 16 Apr 2002 13:53:04 GMT
Server: Apache/1.3.19 (Unix) tomcat/1.0 PHP/4.0.5
Set-Cookie: ID=20020416135310945835; path=/; expires=Tue, 19-Jan-38 03:14:07 GMT
; domain=.xxx.com
Pragma: no-cache
Cache-Control: no-cache
Expires: Friday, 7-Sep-1990 00:00:00 GMT
Last-Modified: Tue, 12 Feb 2002 17:09:19 GMT
ETag: "b7684-a9-3c694c3f"
Accept-Ranges: bytes
Content-Length: 169
Content-Type: text/html
------------------------- >8


---------------------------------------------------------------------
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
For additional commands, e-mail: users-help@httpd.apache.org


Re: redirect directive: avoiding recursive loop

Posted by Joshua Slive <jo...@slive.ca>.
On Tue, 16 Apr 2002, Matthew Pearce wrote:

> I have multiple hosts using the same IP address. How do I get the all
> valid urls to redirect one host. To understand what I am asking try
> launching your browser and enter the url http://sun.com. You'll see
> that the url changes to http://www.sun.com I have tried to do this in
> Apache using the Redirect directive in mod_alias.

Try this:
NameVirtualHost *

<VirtualHost *>
ServerName doesnt.matter.catches.everything.except.www.xxx.com
Redirect permanent / http://www.xxx.com/
</VirtualHost>

<VirtualHost *>
ServerName www.xxx.com
DocumentRoot D:/Apache/htdocs/manual/vhosts/
</VirtualHost>

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
For additional commands, e-mail: users-help@httpd.apache.org