You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Pete Nelson <pe...@ci.stpaul.mn.us> on 2003/01/07 18:12:20 UTC

[users@httpd] mod_rewrite advice

I've set up some rewrite rules on my server to send a different
stylesheet to Netscape 4 browsers.  If a request comes in for
'/css/style.css' from NS4, the server checks for '/css/style-ns4.css',
and if it exists, it send that instead.

The rules I have set up work fine, and are as follows (I already use
BrowserMatch to set the env var NOCSS for the appropriate browsers):

   RewriteCond %{REQUEST_URI} !.*-ns4.css
   RewriteCond %{ENV:NOCSS} =1
   RewriteCond %{REQUEST_URI} (.*).css
   RewriteCond %{DOCUMENT_ROOT}%1-ns4.css -f
   RewriteRule ^(.*)\.css $1-ns4.css

My question is one of performance.  The first conditution simply tells
it to quit processing if the request is already for a custom NS4
stylesheet.  NS4 hits account for only about 2% of our traffic, so the
second condition immediatly ends the processing for the majority of
requests.  The 3rd condition ends the processing if the request is NOT
for a stylesheet, and finally, the 4th condition looks to see if the
alternate stylesheet exists.

Is there a better ordering I could be using for these rules/conditions? 
Any suggestions welcome.


--
Pete Nelson, Web Developer
<pe...@ci.stpaul.mn.us>
http://www.ci.stpaul.mn.us/

Re: [users@httpd] mod_rewrite advice

Posted by Joshua Slive <jo...@slive.ca>.
On Tue, 7 Jan 2003, Pete Nelson wrote:
>    RewriteCond %{REQUEST_URI} !.*-ns4.css
>    RewriteCond %{ENV:NOCSS} =1
>    RewriteCond %{REQUEST_URI} (.*).css
>    RewriteCond %{DOCUMENT_ROOT}%1-ns4.css -f
>    RewriteRule ^(.*)\.css $1-ns4.css
>
> My question is one of performance.  The first conditution simply tells
> it to quit processing if the request is already for a custom NS4
> stylesheet.  NS4 hits account for only about 2% of our traffic, so the
> second condition immediatly ends the processing for the majority of
> requests.  The 3rd condition ends the processing if the request is NOT
> for a stylesheet, and finally, the 4th condition looks to see if the
> alternate stylesheet exists.
>
> Is there a better ordering I could be using for these rules/conditions?
> Any suggestions welcome.

There is no problem with the ordering.  All tests except the -f will be
very fast, so listing the -f last is the way to go.

But you should be aware of another effect of this configuration: A "Vary:
User-Agent" header should be getting added to the HTTP response to alert
caches to the browser-dependent content.  (If Apache isn't adding this
header itself, you should add it manually with the Header directive to
assure that the right browsers get the right content.)  This, in turn,
will reduce the cachability of your responses, and make them uncachable
altogether for all the stupid caches that throw out any response with a
Vary: header.

For this reason (among other), many people use other CSS hiding techniques
to trick Netscape 4.  A simple search turns up many ideas:
http://www.google.com/search?q=hide+css+netscape+4

Joshua.

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