httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Krist van Besien <krist.vanbes...@gmail.com>
Subject Re: [users@httpd] What is wrong with this RewriteCond?
Date Fri, 18 Dec 2009 08:31:18 GMT
Enable RewriteLog, with a high RewriteLogLevel. That way you see in
great detail exactly what is happening.

You'll see what matches are tried, against what strings, what matches
are successfull, what rules are considered. Etc...

BTW, but this is advanced stuff, there is a trick to make whole blocks
of RewriteRules depend on one Condition.

1) You can "Chain" rules together. That way a whole block is
evaluated, or skipped based on wether the first one matches. This is
quite handy with a dummy rule...
(Note how the last rule in your block doesn't have the "C" Flag, and
your first rule must be a "dummy" one that always matches, or your
RewriteCond never gets evaluated.)

# First block, executed when cookie not set.
RewriteCond  %{HTTP_COOKIE} !^.*test=test.*$
RewriteRule -* -   [C]
RewriteRule /inbox$ /index.php [C]
RewriteRule /compose-mail$ /index.php

# Second block, executed when cookie set.
RewriteCond %{HTTP_COOKIE} ^.*test=test.*$
RewriteRule -* -   [C]
RewriteRule /inbox$ http://127.0.0.1:22131/ [P,C]
RewriteRule /inbox/(.+) http://127.0.0.1:22131/$1 [P,C]
RewriteRule /(js/qui.+) http://127.0.0.1:22131/$1 [P,C]
RewriteRule /(css/qui.+) http://127.0.0.1:22131/$1 [P,C]
RewriteRule /js/soundmanager2-nodebug-jsmin.js
http://127.0.0.1:22131/js/soundmanager2-nodebug-jsmin.js [P,C]
RewriteRule /sound/soundmanager2.swf
http://127.0.0.1:22131/sound/soundmanager2.swf [P,C]
RewriteRule /images/favicon.png http://127.0.0.1:22131/images/favicon.png [P,C]
RewriteRule /(e/.+) http://127.0.0.1:22131/$1 [P,C]
RewriteRule /compose-mail$ /proxy/ [C]
RewriteRule /compose-mail/(.+)$ /proxy/$1

2) You can use the "S=x" flag, which tells the RewriteEngine to skip
the next x rules, togethet with a dummy rule. Like this:

# Skip the next two rules when the cookie matches.
RewriteCond  %{HTTP_COOKIE} ^.*test=test.*$
RewriteRule .* - [S=3]

# These rules are executed when the cookie doesn't match.

RewriteRule /inbox$ /index.php [C]
RewriteRule /compose-mail$ /index.php
RewriteRule .* - [S=10]

# These rules are executed when the cookie matches.
RewriteRule /inbox$ http://127.0.0.1:22131/ [P,C]
RewriteRule /inbox/(.+) http://127.0.0.1:22131/$1 [P,C]
RewriteRule /(js/qui.+) http://127.0.0.1:22131/$1 [P,C]
RewriteRule /(css/qui.+) http://127.0.0.1:22131/$1 [P,C]
RewriteRule /js/soundmanager2-nodebug-jsmin.js
http://127.0.0.1:22131/js/soundmanager2-nodebug-jsmin.js [P,C]
RewriteRule /sound/soundmanager2.swf
http://127.0.0.1:22131/sound/soundmanager2.swf [P,C]
RewriteRule /images/favicon.png http://127.0.0.1:22131/images/favicon.png [P,C]
RewriteRule /(e/.+) http://127.0.0.1:22131/$1 [P,C]
RewriteRule /compose-mail$ /proxy/ [C]
RewriteRule /compose-mail/(.+)$ /proxy/$1

# Processing continues here.

With these flags it's quite possible to make quite complex conditional
structures. I once inherited a server where every request was checked
against 200+ rules. By some clever "if-then-else" logic implemented
using dummy rules and the S flag I managed to reduce that all to just
a handfull of tests for each request :-)

Krist
(Disclaimer: I'm currently on the train to work with no way to test
this... This is all of the top of my head.)


-- 
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

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


Mime
View raw message