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