Stop mod_rewrite processing rules on .css, .js, .png etc
am 07.06.2007 17:55:52 von henry.richards
My question is - is there a setting which can modify this behaviour to
prevent mod_rewrite processing rules on the CSS, JS, IMAGE... files
once the redirect has occurred?
To explain in detail...
I have a pretty simple setup. My .htaccess contains something like
the following:
###
RewriteEngine on
RewriteBase /file/
RewriteRule ^thispage(/?)$ page.php?page=2&this=1 [NC,L]
###
Basically it works but looking through the log file I can see that
after the INTERNAL REDIRECT for the main page, all the CSS, JS and
IMAGES on the page are then processed through every rule in
the .htaccess.
It seems a bit crazy that apache does this! It seems like it's taking
a lot of effort and I'm pretty sure it's unnecessary. In fact I
included a rule to work around it:
RewriteRule ^(.*)\.(css|js|php|html|ico|jpg|jpeg|png|gif|ico)$ - [L]
The problem is that this still means every single file included is run
through for every page on my site!
My question is - is there a setting which can modify this behaviour to
prevent mod_rewrite processing rules on these included files once the
redirect has occurred?
Thanks in advance! Really appreciate any help - mod_rewrite has given
me many headaches :)
Henry
Re: Stop mod_rewrite processing rules on .css, .js, .png etc
am 07.06.2007 18:54:39 von shimmyshack
On Jun 7, 4:55 pm, henry.richa...@gmail.com wrote:
> My question is - is there a setting which can modify this behaviour to
> prevent mod_rewrite processing rules on the CSS, JS, IMAGE... files
> once the redirect has occurred?
>
> To explain in detail...
>
> I have a pretty simple setup. My .htaccess contains something like
> the following:
>
> ###
>
> RewriteEngine on
>
> RewriteBase /file/
>
> RewriteRule ^thispage(/?)$ page.php?page=2&this=1 [NC,L]
>
> ###
>
> Basically it works but looking through the log file I can see that
> after the INTERNAL REDIRECT for the main page, all the CSS, JS and
> IMAGES on the page are then processed through every rule in
> the .htaccess.
>
> It seems a bit crazy that apache does this! It seems like it's taking
> a lot of effort and I'm pretty sure it's unnecessary. In fact I
> included a rule to work around it:
>
> RewriteRule ^(.*)\.(css|js|php|html|ico|jpg|jpeg|png|gif|ico)$ - [L]
>
> The problem is that this still means every single file included is run
> through for every page on my site!
>
> My question is - is there a setting which can modify this behaviour to
> prevent mod_rewrite processing rules on these included files once the
> redirect has occurred?
>
> Thanks in advance! Really appreciate any help - mod_rewrite has given
> me many headaches :)
>
> Henry
whatever your rules, mod_rewrite has to check that for each request,
the rules should not be processed, therefore you should have a
condition that stops mod_rewrite as early as possible, as you tried to
do.
If ^thispage(/?)$ never exists, ie. this is just something you would
like to appear in the URL, but which is not present in the filesystem,
(so that if mod_rewrite was turned off the URLs would fail) then you
can use
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
before your RewriteRule
however, it they exist and you only want files with .php to be passed
to the page.php script, then you could use
RewriteCond %{REQUEST_FILENAME} \.php$
before the RewriteRule
no files with any other extensions would then be run through the
rules, _but_ of course they will be looked at, and ignored as soon as
possible, does this make sense to you?
Re: Stop mod_rewrite processing rules on .css, .js, .png etc
am 08.06.2007 09:11:40 von henry.richards
> whatever your rules, mod_rewrite has to check that for each request,
> the rules should not be processed, therefore you should have a
> condition that stops mod_rewrite as early as possible, as you tried to
> do.
Ahh.. Ok.
> If ^thispage(/?)$ never exists, ie. this is just something you would
> like to appear in the URL, but which is not present in the filesystem,
> (so that if mod_rewrite was turned off the URLs would fail) then you
> can use
>
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
>
> before your RewriteRule
Ah. I've seen this before (and used it ;)) but never properly
understood what it was for!
> however, it they exist and you only want files with .php to be passed
> to the page.php script, then you could use
> RewriteCond %{REQUEST_FILENAME} \.php$
> before the RewriteRule
This is a great idea. Thanks.
> no files with any other extensions would then be run through the
> rules, _but_ of course they will be looked at, and ignored as soon as
> possible, does this make sense to you?
That really clears things up. I've been thinking about making a
'fake' filesystem. IE having the folders there for real but having
only .htaccess inside. I think I'll use a combination of the methods.
Thanks!