Project

General

Profile

mod_rewrite documentation, huh?

Added by heavyhttpd over 16 years ago

Hello,

I'm trying to figure out the semantics of url.rewrite-* from mod_rewrite (http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModRewrite) and have some questions. Hopefully, someone familiar with how mod_rewrite works will be able to answer them.

1. First, I'm confused about the difference between url.rewrite-once and url.rewrite-repeat. The docs say

while url.rewrite-repeat allows for applying multiple (seperately defined) rewrite rules in a row, url.rewrite-once will cause further rewrite rules to be skipped if the expression was matched

But what does "multiple rules" mean? Is it referring to something like this:

url.rewrite-once = ( "^/id/([0-9]+)$" => "/index.php?id=$1" )
url.rewrite-once = ( "^/link/([a-zA-Z]+)" => "/index.php?link=$1" )

or something like this:

url.rewrite-once = ( "^/id/([0-9]+)$" => "/index.php?id=$1",
                     "^/link/([a-zA-Z]+)" => "/index.php?link=$1" )

Are the rewrite rules cumulative, or do latter settings override former settings?

2. The docs provide this example:

server.document-root = "/www/htdocs/" 
$HTTP["host"] =~ "^.*\.([^.]+\.com)$" {
  url.rewrite-once = ( "^/(.*)" => "/%0/$1" )
}

# request:        http://any.domain.com/url/ 
# before rewrite: REQUEST_URI="/www/htdocs/url/" 
# and DOCUMENT_ROOT="/www/htdocs/" %0="any.domain.com" $1="url/" 
# after rewrite:  REQUEST_URI="/www/htdocs/any.domain.com/url/" 
# still, you have DOCUMENT_ROOT=/www/htdocs/

But it looks like there are errors in the example... is the REQUEST_URI supposed to contain the prefix "/www/htdocs/"? I thought the REQUEST_URI in this case would be "/url". Also, "%0" doesn't seem to match the entire domain name as shown in the example. Wouldn't "%0" substitute just "domain.com", rather than "any.domain.com"?

3. The docs also say:

If you wanna pass the Query String (?foo=bar) to the rewrite destination you have to explicitly match it

And give an example of query string mangling. I was under the impression that url.rewrite-* always operated on the query string. Should this say, instead:

If you want to rewrite the Query String (?foo=bar) to the rewrite destination you have to explicitly match it

?

4. Also, does the REQUEST_URI contain the URL scheme? i.e.:

GET http://example.com/index.php?foo=bar HTTP/1.1
Connection: close

Would QUERY_STRING contain "http://example.com/index.php?foo=bar" or just "/index.php?foo=bar"?

Clarification of these issues would be greatly appreciated. Much thanks!