Rewrite rules for static cache

Author Message

Fabrice Girardot

Monday 15 October 2007 6:31:08 am

Hi,

I'm currently trying to deal with rewrite rules as describe there :http://ez.no/developer/articles/ez_publish_performance_optimization_part_3_of_3_practical_cache_and_template_solutions/static_cache

So, this is what I want to do: The web site have several siteaccess that I want to cache. Let call them "site1" and "site2". The static cache is generated into static/site1 and static/site2.

According to the article, I put this in the .htaccess (I do not have access to httpd.conf):

RewriteEngine On

RewriteCond /home/www/static/site1/index.html -f
RewriteRule ^/$            /static/site1/index.html [L]
RewriteCond /home/www/static/site1/index.html -f
RewriteRule ^$            /static/site1/index.html [L]
 
RewriteCond /home/www/static/site2/index.html -f
RewriteRule ^/$            /static/site2/index.html [L]
RewriteCond /home/www/static/site2/index.html -f
RewriteRule ^$            /static/site2/index.html [L]
  
RewriteCond %{REQUEST_METHOD}     !^POST$
RewriteCond /home/www/static$1/index.html -f
RewriteRule ^(.*)$ /static$1/index.html [L]
 
RewriteRule !\.(gif|css|jpg|png|jar|ico|js)$ /index.php

It doesn't work. When I access to http://mysite.com/index.php/site1, it don't access to the static cache wich is supposed to be http://mysite.com/static/site1/

So, my question is simple : is the code I put in the .htaccess file is good and should work or not?

I am completely lost, if someone can help, it will be really appreciated.

--
Fabrice

Cemil Giray

Tuesday 06 November 2007 2:09:04 am

Hi. Anyone have any solutions for this one?

Messages must cause change.

Stefan de Bruijn

Tuesday 06 November 2007 8:33:56 am

Have you checked what exactly is generated in /static/site1 and static/site2?

the url http://mysite.com/index.php/site1 would translate to:
/home/www/static/index.php/site1/index.html
So first loose the 'index.php'.

I never use static cache for multiple siteaccess in one Ez Publish installation (easier to make multiple installations).
IF it's going to work: you have to have the siteaccess name in your url. ( like http://mysite.com/site1 and http://mysite.com/site2)

According to the instructions :
"You should only add rewrite rules for the VHOSTs for which you want to have static caching. <i>In reality, this means that for each siteaccess that you want to cache, you need a different VHOST block in the Apache configuration.</i>"

I use different rewrite rules (works for 1 siteaccess, could work if you have the siteaccess name in your url, and the /static/site1 and /static/site2 are correctly generated). Example:

RewriteEngine On
# static cache in ez
# no cache for http posts
RewriteCond   %{REQUEST_METHOD} !^POST$
# do not cache vhost admin
RewriteCond   %{HTTP_HOST} !^admin.*$
# non caching vhost for passing the static cache
RewriteCond   %{HTTP_HOST} !^nocache\.mydomain\.nl$
# Does the index.html exist in the static cache?
RewriteCond   /srv/www/dbcc/static$1/index.html -f
#rewrite to the static cache
RewriteRule   ^(.*)$  /static$1/index.html [L]

#default ez rewrites
Rewriterule ^/var/storage/.* - [L]
Rewriterule ^/var/[^/]+/storage/.* - [L]
RewriteRule ^/var/cache/texttoimage/.* - [L]
RewriteRule ^/var/[^/]+/cache/texttoimage/.* - [L]
Rewriterule ^/design/[^/]+/(stylesheets|images|javascript)/.* - [L]
Rewriterule ^/share/icons/.* - [L]
Rewriterule ^/extension/[^/]+/design/[^/]+/(stylesheets|images|javascripts?)/.* - [L]
Rewriterule ^/packages/styles/.+/(stylesheets|images|javascript)/[^/]+/.* - [L]
RewriteRule .* /index.php

If it works, you still have to make a page for 'http://mysite.com/' (or point it to one of the 2 siteaccess). you could use:

# rewrite homepage only
# check for index.html
RewriteCond   $1 =/ [OR]
RewriteCond   $1 =""
RewriteCond   /srv/www/dbcc/static/index.html -f 
RewriteRule   ^(.*)$  /static/index.html [L]
#no index.html
RewriteCond   $1 =/ [OR]
RewriteCond   $1 =""
RewriteRule   ^(.*)$  /index.php [L]

You could make a page for letting the visitor choose the siteaccess and point your homepage there

..
RewriteCond   /srv/www/dbcc/static/site1/choose/index.html -f 
RewriteRule   ^(.*)$  /static/site1/choose/index.html [L]
..
RewriteRule   ^(.*)$  /site1/choose/index.php [L]

Stefan de Bruijn

Tuesday 06 November 2007 8:53:08 am

I didn't read the complete instructions on http://ez.no/developer/articles/ez_publish_performance_optimization_part_3_of_3_practical_cache_and_template_solutions/static_cache. There are also instructions on using the cache with multiple site-accesses.

But as far as I understand the rewrite rules (http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html) for the given example don't work:

RewriteCond /home/httpd/ez-3.6/static/news_en/index.html -f
RewriteRule ^/$            /static/news_en/index.html [L]
RewriteCond /home/httpd/ez-3.6/static/news_en/index.html -f
RewriteRule ^$             /static/news_en/index.html [L]

RewriteCond /home/httpd/ez-3.6/static/news_fr/index.html -f
RewriteRule ^/$            /static/news_fr/index.html [L]
RewriteCond /home/httpd/ez-3.6/static/news_fr/index.html -f
RewriteRule ^$             /static/news_fr/index.html [L]

If "RewriteCond /home/httpd/ez-3.6/static/news_en/index.html -f" is true, then the root-url ('mydomain.com/) is rewritten to mydomain/static/news_en/index.html and no further rewrites are done. The french siteaccess will only be used if there is no english static cache?!

Fabrice Girardot

Tuesday 06 November 2007 9:07:30 am

Hi Stefan, thank you very much for your post.

This is the real urls (for a test siteaccess called "wac_test" right now, but all the other static are already done for en/fr/es/pt/ru) :

the dynamic: http://www.worldaidscampaign.info/index.php/wac_test/
and the static: http://www.worldaidscampaign.info/static/wac_test/

The problem is all the links in the static always referred to the dynamic part, so we need to rewrite every "/index.php/wac_test" with "/static/wac_test" (let's keep the other siteaccess dynamic). I have really no idea how I can do this.

--
Fabrice

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 16:24:47
Script start
Timing: Jan 18 2025 16:24:47
Module start 'layout'
Timing: Jan 18 2025 16:24:47
Module start 'content'
Timing: Jan 18 2025 16:24:47
Module end 'content'
Timing: Jan 18 2025 16:24:47
Script end

Main resources:

Total runtime0.6323 sec
Peak memory usage4,096.0000 KB
Database Queries65

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0049 589.3438152.6250
Module start 'layout' 0.00490.0029 741.968839.4453
Module start 'content' 0.00780.6223 781.4141608.9297
Module end 'content' 0.63010.0022 1,390.343816.1641
Script end 0.6322  1,406.5078 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.5385160.0002
Check MTime0.00130.2111160.0001
Mysql Total
Database connection0.00070.116410.0007
Mysqli_queries0.575791.0443650.0089
Looping result0.00060.0891630.0000
Template Total0.603595.420.3018
Template load0.00190.302420.0010
Template processing0.601695.143120.3008
Template load and register function0.00010.021010.0001
states
state_id_array0.00080.124310.0008
state_identifier_array0.00120.196420.0006
Override
Cache load0.00160.2498410.0000
Sytem overhead
Fetch class attribute can translate value0.00060.097730.0002
Fetch class attribute name0.00110.170760.0002
XML
Image XML parsing0.00070.117030.0002
class_abstraction
Instantiating content class attribute0.00000.002270.0000
General
dbfile0.00080.1330160.0001
String conversion0.00000.001640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 31
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs