[SATLUG] Re: When rewrite doesn't
Mike
mzilla1101 at gmail.com
Thu Feb 1 22:59:32 CST 2007
Okay, I have been able to answer my own questions so far. Now, I have a new
one. First, here's a rewrite rule that works. Don't worry about the crazy
syntax of the URL I'm writing to. What's imporant is that rewrite is
applying the rule at the right time.
RewriteRule ^/directory($|/.*) \
http://127.0.0.1:8080/VirtualHostBase/\
http/{SERVER_NAME}:80/stuff/VirtualHostRoot/_vh_directory$1 [L,P]
When I visit http://www.someurl.com/directory, the rewrite log shows what
you would expect to see and I see the expected web page from the other
server.
(2) init rewrite engine with requested uri /directory
(3) applying pattern '^/directory($|/.*)' to uri '/directory'
(2) rewrite /directory ->
http://127.0.0.1:8080/VirtualHostBase/http/{SERVER_NAME}:80/stuff/VirtualHostRoot/_vh_directory
Now, let's say that I would rather that directory/subdir be the path to map
instead of just plain ol directory. In that case, I'll replace the above
rule with the following.
RewriteRule ^/directory/subdir($|/.*) \
http://127.0.0.1:8080/VirtualHostBase/\
http/{SERVER_NAME}:80/stuff/VirtualHostRoot/_vh_directory/_vh_subdir$1 [L,P]
Now, when I visit http://www.someurl.com/directory/subdir, the rewrite log
shows something strange.
(2) init rewrite engine with requested uri /directory/subdir
(3) applying pattern '^/directory/subdir($|/.*)' to uri '/directory/subdir'
(1) pass through /directory/subdir
Huh? So, when the pattern is just a single directory, it's able to match.
When the pattern is multiple directories, it doesn't match. And of course
the page returned in this case is the classic Apache 404 saying that
/directory/subdir doesn't exist. So, why does rewrite catch the first case,
but not the second?
-Mike
More information about the SATLUG
mailing list