|
Home > Archive > Apache Server configuration support > February 2006 > rewrite inherit within virtual hosts
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
rewrite inherit within virtual hosts
|
|
| Jim Hayter 2006-02-26, 11:24 am |
| Apache 1.3.33 on Solaris 9 and 10
I have some rewrite rules that I want to apply within all my virtual hosts:
------------------------ begin --------------------------------
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
# special robots.txt for secure server - discourage crawling vis https
<IfDefine SSL>
RewriteRule ^/robots.txt$ /robots_https.txt
</IfDefine>
</IfModule>
------------------------- end ---------------------------------
I placed the above in my configuration file along with the RewriteLog
and RewriteLogLevel directives.
In each virtual host I placed:
------------------------ begin --------------------------------
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteOptions inherit
<vhost specific rewrite rules>
</IfModule>
------------------------- end ---------------------------------
From my reading of the RewriteOptions directive for Apache 1, the
"inherit" option should cause the virtual host to pull in the server
rewrite rules listed first above. From the rewrite log, this is not
happening.
Is my understanding of how this works incorrect or am I doing something
wrong trying to implement it?
Thanks,
Jim
| |
| Robert Ionescu 2006-02-26, 11:24 am |
| Jim Hayter wrote:
> RewriteEngine on
> RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
> RewriteRule .* - [F]
[...]
> RewriteRule ^/robots.txt$ /robots_https.txt
You might simplify the regEx to
RewriteRule ^ - [F]
and escape the period so that it becomes a literal period rather than
any character (^/robots\.txt$)
> In each virtual host I placed:
> ------------------------ begin --------------------------------
> <IfModule mod_rewrite.c>
> RewriteEngine on
> RewriteOptions inherit
>
> <vhost specific rewrite rules>
And what in specific? This is important, see below
> From my reading of the RewriteOptions directive for Apache 1, the
> "inherit" option should cause the virtual host to pull in the server
> rewrite rules listed first above. From the rewrite log, this is not
> happening.
Yes, it works for me both with apache 1.3.34 and apache 2.0.55, but the
RewriteRules placed inside the main server config section are evaluated
after the RewriteRules placed within your <virtualhost>.
Now, if a rule from within your <virtualhost> did match and you did set
the [L] flag, all rules below wouldn't be processed anymore. This is the
intention of the L-flag, of course. So far so good, but this does
include that the rules from the main server config section wouldn't be
processed anymore, too (because they are evaluated after the vhost rules).
This is some kind of tricky, because the order isn't really documented...
If this is not the problem, try to remove all specific rules in order to
test what's happening then.
--
Robert
| |
| Jim Hayter 2006-02-26, 11:24 am |
| Robert Ionescu wrote:
> Jim Hayter wrote:
<snip>
Thanks for the suggestions to improve the rewrite rules.
>
>
>
> Yes, it works for me both with apache 1.3.34 and apache 2.0.55, but the
> RewriteRules placed inside the main server config section are evaluated
> after the RewriteRules placed within your <virtualhost>.
> Now, if a rule from within your <virtualhost> did match and you did set
> the [L] flag, all rules below wouldn't be processed anymore. This is the
> intention of the L-flag, of course. So far so good, but this does
> include that the rules from the main server config section wouldn't be
> processed anymore, too (because they are evaluated after the vhost rules).
> This is some kind of tricky, because the order isn't really documented...
> If this is not the problem, try to remove all specific rules in order to
> test what's happening then.
>
Ah, this is the problem. I made the rash assumption that the inherited
rules would be processed first. I have some new rules I need to
implement early on for each virtual host and was hoping to accomplish it
by putting them at the server level and using inherit.
I guess I'll put them in an include file and pull it in for each virtual
host.
Thanks for the info.
Jim
| |
| Robert Ionescu 2006-02-26, 11:24 am |
| Jim Hayter wrote:
> Robert Ionescu wrote:
[...][vbcol=seagreen]
[...][vbcol=seagreen]
>
> Ah, this is the problem. I made the rash assumption that the inherited
> rules would be processed first. I have some new rules I need to
> implement early on for each virtual host and was hoping to accomplish it
> by putting them at the server level and using inherit.
>
> I guess I'll put them in an include file and pull it in for each virtual
> host.
Or - an other option - modify the source (mod_rewrite.c) and recompile
mod_rewrite:
--- src/modules/standard/mod_rewrite.c.orig taken from source 1.3.33
--- src/modules/standard/mod_rewrite.c
@@ -243,12 +243,12 @@
a->rewritelogfp = overrides->rewritelogfp != -1
? overrides->rewritelogfp
: base->rewritelogfp;
- a->rewritemaps = ap_append_arrays(p, overrides->rewritemaps,
- base->rewritemaps);
- a->rewriteconds = ap_append_arrays(p, overrides->rewriteconds,
- base->rewriteconds);
- a->rewriterules = ap_append_arrays(p, overrides->rewriterules,
- base->rewriterules);
+ a->rewritemaps = ap_append_arrays(p, base->rewritemaps,
+ overrides->rewritemaps);
+ a->rewriteconds = ap_append_arrays(p, base->rewriteconds,
+ overrides->rewriteconds);
+ a->rewriterules = ap_append_arrays(p, base->rewriterules,
+ overrides->rewriterules);
}
else {
/*
--
Robert
| |
| Robert Ionescu 2006-02-26, 11:24 am |
| Jim Hayter wrote:
> I made the rash assumption that the inherited rules would be
> processed first.
BTW: Yes, that is my logical understanding as well. With the current
behavior all results of the processed rules inside the <virtualhost>
section might be changed again by the inherited rules. I think that is
at least in most cases not the intention and might lead to unexpected
results...
--
Robert
|
|
|
|
|