durusmail: quixote-users: RewriteRule
RewriteRule
2002-05-21
2002-05-22
2002-05-22
2002-05-22
2002-05-22
2002-05-23
2002-05-24
2002-05-29
2002-05-29
2002-05-29
2002-05-29
2002-05-29
2002-05-29
2002-05-29
RewriteRule
Greg Ward
2002-05-22
On 21 May 2002, Patrick K. O'Brien said:
> I'm curious about your RewriteRule recommendations. In the demo.txt you've
> got:
>
>     RewriteRule ^/qdemo(/.*) /www/cgi-bin/demo.cgi$1 [l]
>
> First, shouldn't the option be [L] or [last]?o

Oops, thanks -- fixed in CVS.  Apache doesn't seem to care either way,
but consistency is important.

> Second, most of the examples in the Apache docs look more like this:
>
>     RewriteRule ^/qdemo/(.*) /www/cgi-bin/demo.cgi/$1 [last]
>
> That's the pattern I used in my .htaccess file and it works fine.

It doesn't matter.  These two rewrite rules:

  RewriteRule ^/qdemo(/.*) /www/cgi-bin/demo.cgi$1 [last]
  RewriteRule ^/qdemo/(.*) /www/cgi-bin/demo.cgi/$1 [last]

are exactly equivalent.  If you were implementing the regex in
machine-language for processing a billion requests a second, you might
worry about the extra expense of always including the slash in the
paren-group... but I don't think it really matters.

In particular, requests for "/qdemo/" will be handled by both rules, but
requests for "/qdemo" will not.  People are lazy and most people don't
understand the difference between "/qdemo" and "/qdemo/" -- so it's
important that you (the webmaster) take care of it for them.  From
Quixote's demo.txt:

  One small but important detail here is "/qdemo" versus "/qdemo/".  In
  the above configuration, requests for "/qdemo" will fail, and requests
  for "/qdemo/" will succeed.  See the "URL rewriting" section of
  web-server.txt for details and how to fix this.

And from web-server.txt:

          RewriteRule ^/qdemo(/.*) /www/cgi-bin/demo.cgi$1 [last]
  [...]
  Note that requests for "/qdemo/" and "/qdemo" are *not* the same; in
  particular, with the above rewrite rule, the former will succeed and the
  latter will not.  (Look at the regex again if you don't believe me:
  "/qdemo" doesn't match the regex, so demo.cgi is never invoked.)

  The solution for "/qdemo" is the same as if it corresponded to a
  directory in your document tree: redirect it to "/qdemo/".  Apache (and,
  presumaby, other web servers) does this automatically for "real"
  directories; however, "/qdemo/" is just a directory-like chunk of
  URL-space, so either you or Quixote have to take care of the redirect.

  It's almost certainly faster for you to take care of it in the web
  server's configuration.  With Apache, simply insert this directive
  *before* the above rewrite rule:

          RewriteRule ^/qdemo$ /qdemo/ [redirect=permanent]

  If, for some reason, you are unwilling or unable to instruct your web
  server to perform this redirection, Quixote will do it for you.
  However, you have to make sure that the "/qdemo" URL is handled by
  Quixote.  Change the rewrite rule to:

          RewriteRule ^/qdemo(/.*)?$ /www/cgi-bin/demo.cgi$1 [last]

  Now a request for "/qdemo" will be handled by Quixote, and it
  will generate a redirect to "/qdemo/".  If you're using a CGI
  driver script, this will be painfully slow, but it will work.

All clear?

        Greg


reply