rewrite inherit within virtual hosts
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Apache Server configuration support > rewrite inherit within virtual hosts




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    rewrite inherit within virtual hosts  
Jim Hayter


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-26-06 04:24 PM

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





[ Post a follow-up to this message ]



    Re: rewrite inherit within virtual hosts  
Robert Ionescu


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-26-06 04:24 PM

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





[ Post a follow-up to this message ]



    Re: rewrite inherit within virtual hosts  
Jim Hayter


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-26-06 04:24 PM

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





[ Post a follow-up to this message ]



    Re: rewrite inherit within virtual hosts  
Robert Ionescu


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-26-06 04:24 PM

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





[ Post a follow-up to this message ]



    Re: rewrite inherit within virtual hosts  
Robert Ionescu


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-26-06 04:24 PM

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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:04 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register