httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralf S. Engelschall" <...@en.muc.de>
Subject Re: mod_rewrite v2.2-SNAP (II)
Date Wed, 07 Aug 1996 20:53:24 GMT
On 7 Aug 1996 22:14:27 +0200 in en.lists.apache-new-httpd you wrote:
> On Wed, 7 Aug 1996, Ralf S. Engelschall wrote:

> > Now, the current mod_rewrite v2.2-SNAP has all requests from Alexei included.
> > Have a look at the ChangeLog at
> > http://www.engelschall.com/sw/mod_rewrite/arc/mod_rewrite-SNAP/ChangeLog
> > to see what stuff was changed (a lot of code changed!).

> Okay... I've looked at this version, played around with it a bit, and I
> can now say I'm *almost* happy with it. There's just one little thing I'd
> like changed:

> Remove the reduce_uri() function and any calls to it. It has some problems
> that cause it to not work right when you're not running your server on
> port 80. But more than that, it's a bad idea. There is a very good reason
> to issue an external redirect to yourself - so relative links work. This
> is why all web servers in existance either require that you have a
> trailing slash on directories, or issue a redirect so that you end up with
> one. If you "transparently" change external redirects into internal
> redirects, you cause confusion.

Correct, a external redirect to oneself _IS_ useful. I myself use this
"redirect of trailing slash is missing" feature in my rewriting rules. It is
one of mod_rewrites main features!

BUT: To do this, there is the [R] option, which means "_force_ a external
redirect". Only prefixing the substitution part by http://thishost/ is not
enough. If you really want a external redirection to happen, then you have to
additionally place a [R] at this rule. This difference is important and no
mistake by myself!

I will explain why this automatic-reducement _IS_ really useful _AND_ needed.
Look at the following rules in the per-server config of "thishost" as an
example (with the _CURRENT_ behaviour of mod_rewrite in mind!):

RewriteRule ^/IN1     http://thishost/OUT1
RewriteRule ^/IN2     http://thishost/OUT2   [R]
RewriteRule ^/IN3     http://otherhost/OUT3
RewriteRule ^/IN4     http://otherhost/OUT4  [R]

- The first one gets reduced to /OUT1.
- The second one leads to a external redirect to the server itself via new
  URL /OUT2.
- The third one is a implicit redirection, and leads to a external
  redirection to "otherhost".
- The fourth one is a explicit redirection and also leads to
  a external redirection to "otherhost".

You know this and say "Ok, then the first one is silly because the prefix is
allways stripped and last ones are silly because of the format of the third
works as equal". And now I say "NO", because this is only the case in such a
_STATIC_ example. Here the differences between implicit and explicit
redirections and the automatic reducement _SEEMS_ inconsistent and badly
designed.

Now, remember that mod_rewrite also has support for _DYNAMIC_ rules, i.e ones
which only _LOOK_ static, but can be really different at each instance!  How?
Remember the RewriteMap directive and its uses!

The _FIRST_ example in the example section of the mod_rewrite documentation
shows you such _DYNAMIC_ substitutions. Here the above statements are wrong
and you will say "Puhhh... nice to have these important differences!"

Let me give this example: You have more than one machine and a great amount
of users spread accross these webservers. Now you want, that the URL "/~user"
is valid _ON ALL SERVERS_! (I named this ``homogeneous URL layout''). To get
the trick you have only two possibilities: Either specify a stand-alone rule
for each user which either redirects it to another server or keep it locally.
Or you use mod_rewrite! 

You setup a mapfile consisting of the following entries

   <user1>    <drophost_for_user1>
   <user2>    <drophost_for_user2>
   :
   <user1>    <drophost_for_user1>

end spread it across the servers (via rdist or HTTP) (say filename
/path/to/mapfile). Then on the webserver "drophostX" you just have the
following config:

ServerName    drophostX
RewriteEngine On
RewriteMap    user-to-host     txt:/path/to/mapfile
RewriteRule   ^/~([^/]+)(.*)   http://${user-to-host:$1|drophostX}/~$1$2

This actually does the trick! BUT ONLY BECAUSE OF THE EXISTING
AUTO-REDUCEMENT!

When a user maps to drophostX or is still not in the map
is should be local. In this example the substitution first gets
   http://drophostX/~user/...
and then 
   /~user/...
THIS IS IMPORTANT! If mod_rewrite would _allways_ do a external redirect when
it sees http://anyhost/ this leads to a never ending loop!

And there are more examples...

FINALLY let me conclude: 
The auto-reduction _REALLY IS_ useful and important and should not be removed!

> Except for that one little change (which amounts to just deleting a dozen
> lines of code - a no-brainer), I can now say (at least for now), that I am
> very happy with the current snapshot of mod_rewrite, and am in support of
> including mod_rewrite.c in Apache 1.2, and in the default Configuration.

Fine. But please rethink about the requested removement of the reduce_uri()
stuff.

Greetings,
                                        Ralf S. Engelschall    
                                        rse@engelschall.com
                                        http://www.engelschall.com/~rse

Mime
View raw message