You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Aaron Morris <aa...@mindspring.com> on 2003/06/20 23:31:16 UTC

[users@httpd] Modifing the behavior of mod_dir redirects

I want to pose a question to the user list before trying the developers 
list.

AIX 5.1 ML3
Apache 1.3.26 (actually IBM HTTP Server 1.3.26)

I having a problem with the redirect behavior in mod_dir.  In my 
environment, when a request comes in, a NAT device changes the 
destination address as well as the destination port.  When the response 
is sent back, the device changes the source IP and the source port. 
Standard static NATing.  The problem comes in when mod_dir redirects 
requests for directories without a trailing slash.

ie  A request to "http://httpd.apache.org/docs", mod_dir issues a 301 
redirect to "http://httpd.apache.org/docs/".  In my environment, since 
Apache receives the request on a different port number the redirect 
reflects the internal port number instead of the port from the 
perspective of the internet.  ie  "http://httpd.apache.org:10000/docs/"

I have a workaround using mod_rewrite:

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
RewriteRule ^/(.+[^/])$ http://%{HTTP_HOST}/$1/ [R]

This works for HTTP requests, but HTTPS requests (in IBMs IHS SSL 
module, not sure about mod_ssl), apparently, do not pass through 
mod_rewrite, so the standard mod_dir behavior applies.  It seems to me 
that it might be worth the effort to be able to modify the behavior of 
the mod_dir redirects.  Something like a directive to tell mod_dir to 
use the HOST header for the redirect.

I know my environment is not a standard setup, but I also know that it 
is not all that unusual.  I just wanted to bounce this idea off this 
list before moving it up the developers list.  Any feedback would be great.

Thanks.

-- 
Aaron W Morris <aa...@mindspring.com> (decep)
PGP Key ID:  259978D1



---------------------------------------------------------------------
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] Modifing the behavior of mod_dir redirects

Posted by Aaron W Morris <aa...@mindspring.com>.
On Fri, 2003-06-20 at 18:46, Joshua Slive wrote:
> On Fri, 20 Jun 2003, Aaron Morris wrote:
> > ie  A request to "http://httpd.apache.org/docs", mod_dir issues a 301
> > redirect to "http://httpd.apache.org/docs/".  In my environment, since
> > Apache receives the request on a different port number the redirect
> > reflects the internal port number instead of the port from the
> > perspective of the internet.  ie  "http://httpd.apache.org:10000/docs/"
> 
> Set
> UseCanonicalName On
> Listen 80
> Port 10000
> 
> Check the docs on all three of these directives (as well as ServerName).
> You'll see that, when a Listen directive is present, the Port directive
> does not set the actual port used by apache, but only the port used in
> redirects (and similar self-identifying actions).

I appreciate the info; it really helped me understand the purpose of
those directives.  While reading the info about "UseCanonicalName" I
realized that the docs are actually incorrect when it talks about how
Apache gets the port information.

Quoted from the Apache docs:
"With UseCanonicalName off Apache will form self-referential URLs using
the hostname and port supplied by the client if any are supplied..."

It looks like Apache completely ignores port information supplied by the
client.


------------
ws001[/home/user]$ nc -v localhost 12175
loopback [127.0.0.1] 12175 (?) open
GET /images HTTP/1.0
Host: www.blah.com:81

HTTP/1.1 301 Moved Permanently
Date: Mon, 23 Jun 2003 18:39:13 GMT
Server: IBM_HTTP_SERVER
Location: http://www.blah.com:12175/images/
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>301 Moved Permanently</TITLE>
</HEAD><BODY>
<H1>Moved Permanently</H1>
The document has moved <A
HREF="http://www.blah.com:12175/images/">here</A>.<P>
</BODY></HTML>
------------

Is this a bug or are the docs wrong?

> 
> 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
> 

---------------------------------------------------------------------
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] Modifing the behavior of mod_dir redirects

Posted by Joshua Slive <jo...@slive.ca>.
On Fri, 20 Jun 2003, Aaron Morris wrote:
> ie  A request to "http://httpd.apache.org/docs", mod_dir issues a 301
> redirect to "http://httpd.apache.org/docs/".  In my environment, since
> Apache receives the request on a different port number the redirect
> reflects the internal port number instead of the port from the
> perspective of the internet.  ie  "http://httpd.apache.org:10000/docs/"

Set
UseCanonicalName On
Listen 80
Port 10000

Check the docs on all three of these directives (as well as ServerName).
You'll see that, when a Listen directive is present, the Port directive
does not set the actual port used by apache, but only the port used in
redirects (and similar self-identifying actions).

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