Forums / Developer / Rewrite rules for static cache

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

eZ debug

Timing: Jan 18 2025 11:33:17
Script start
Timing: Jan 18 2025 11:33:17
Module start 'content'
Timing: Jan 18 2025 11:33:18
Module end 'content'
Timing: Jan 18 2025 11:33:18
Script end

Main resources:

Total runtime1.2381 sec
Peak memory usage4,096.0000 KB
Database Queries202

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0067 587.7109180.8359
Module start 'content' 0.00671.0913 768.5469614.0078
Module end 'content' 1.09800.1400 1,382.5547341.3750
Script end 1.2381  1,723.9297 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00530.4257210.0003
Check MTime0.00170.1341210.0001
Mysql Total
Database connection0.00110.085110.0011
Mysqli_queries1.154193.21032020.0057
Looping result0.00210.16942000.0000
Template Total1.199696.920.5998
Template load0.00250.199720.0012
Template processing1.197196.684120.5985
Template load and register function0.00010.008810.0001
states
state_id_array0.00160.127010.0016
state_identifier_array0.00110.090920.0006
Override
Cache load0.00220.1810410.0001
Sytem overhead
Fetch class attribute can translate value0.00310.250640.0008
Fetch class attribute name0.00270.215260.0004
XML
Image XML parsing0.00110.090440.0003
class_abstraction
Instantiating content class attribute0.00000.001370.0000
General
dbfile0.00220.1755270.0001
String conversion0.00000.000330.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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