Hi.

> The documentation for mod_rewrite states the following for the [C]
> flag:
>
>
>  For instance, use it to remove the ``.www'' part inside a
> per-directory
> rule set when you let an external redirect happen (where the ``.www''
> part should not to occur!).

I think this note is based upon an example in the rewrite guide:

RewriteEngine on
RewriteCond   %{HTTP_HOST}  ^www\.[^.]+\.host\.com$
RewriteRule   ^(.+)    %{HTTP_HOST}$1 [C]
RewriteRule   ^www\.([^.]+)\.host\.com(.*) /home/$1$2

but the same can be also achieved with

RewriteEngine on
RewriteCond   %{HTTP_HOST}  ^www\.([^.]+)\.host\.com$
RewriteRule   ^/(.+)     /home/%1/$2 [L]

may be more useful: an other trailing slash fix (per-dir context)

RewriteEngine On
RewriteRule !^.+\.[a-z]{2,4}$ - [C]
RewriteRule ^(.+[^/])$ /$1/ [R=301,L]

The difference is: With that one in the rewrite guide, rule and condition are tested. With this one, the pattern is tested if there's no extension present. Only if this is the case, the 2nd rule with the wide and slow RegEx .+ is tested against the filepath, if there is no trailing slash present. Of course, this snippet doesn't check, if the path is an existing directory at all, but if you don't have extension-less files, nothing could go wrong.

With this one from the rewrite guide,
RewriteCond    %{REQUEST_FILENAME}  -d
RewriteRule    ^(.+[^/])$           $1/  [R]

rule-pattern and condition are always tested for every request (if no trailing slash is present). So every /abc.html request would be testet against the rule + condition.


An other case might be: Setting ENVs

RewriteRule ^abc - [E=var1:test,C]
RewriteRule \.html$ - [E=ext:html,L]

If the filepath starts with abc, the env var1:test will be set.
(If it starts with abc CHAINED) and ends with .html, E=ext:html would be set additionally.

Of course, the following does the same:
RewriteRule ^abc - [E=var1:test]
RewriteRule ^abc.*\.html$ - [E=ext:html,L]

There are sometimes different ways to create a ruleset - one is using the C-Flag... :-)

HTH,
Robert

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to