This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Install & configuration » Static cache and .htaccess
expandshrink

Static cache and .htaccess

Static cache and .htaccess

Saturday 06 September 2014 7:17:28 am - 12 replies

Hi all

I am using a 4.x (2012.6) and wish to make use of static cache in a site.

I've searched all over, attempted several options, but I can't manage to find the proper rewrite rules to place in .htaccess.

Can anyone point out the correct setup to use?

Thank you, in advance,

Io

Saturday 06 September 2014 6:38:27 pm

Hello lo Sol Inf,

See if reading this documentation about the static cache feature does not help.

https://github.com/ezsystems/ezpublish-legacy/blob/master/doc/features/3.6/staticcache.txt

Let me know if you have any more questions!

Cheers,
Heath 

Saturday 06 September 2014 6:51:52 pm

Hi Heath

Thank you for your input. I had stumbled on those rewrite rules in an old post already. Unfortunately, those don't seem to work in a .htaccess (those seem to be meant for a vhost configuration file).

I am not sure if it is relevant to understand the issue that I am facing, but I am supporting multiple sites, under a single eZ Publish installation. Therefore, I have multiple databases and a host_uri combination to identify with site (siteaccess settings) to use. My goal is to have static cache for only one of those sites (for the time being, the remaining sites don't actually benefit from static caching).

Cheers,
Io

Saturday 06 September 2014 9:17:19 pm

Hello lo Sol Inf,

Now I understand. They did not provide .htaccess rules in the documentation.

Update! I used an ezpedia test vhost to setup static cache for the site (we used to use it there).

These example rules worked well for a complete static cache setup:

Also note that I placed my static rules above the default ezpublish legacy rewrite rules. This is important!

EDIT: I have posted my complete full .htaccess file as a gist from here: https://gist.github.com/brookinsconsulting/768cab49180dcc2c4a7d

I hope this helps!

Cheers,
Heath

Modified on Sunday 07 September 2014 1:37:52 am by // Heath

Sunday 07 September 2014 3:58:49 pm

Hi again

I had already posted this reply, but it was lost somehow sad.gif Emoticon

I've updated my settings, adapting what you suggested, but I'm running into an odd behavior when I attempt to run makestaticcache script.

Nothing is generated in my static storage, and I read the following in error.log

Static Cache:
Could not grab content (from http://examplesite.com/examplesite.com/Board

staticcache.ini has the following:

[CacheSettings]
HostName=examplesite.com
StaticStorageDir=static
MaxCacheDepth=5
CachedURLArray[]
CachedURLArray[]=/Board

Edited: After a few more tests I was able to verify that the URl being fetched was http://<[CacheSettings]HostName>/<Actual URl of the page>.

If I set [CacheSettings]HostName to a nothing, the static cache is properly set, that seemed totally wrong, but after reading this comment in the code, I am not so sure...

Do I need to setup a fake host+port to generate the static content?

Modified on Sunday 07 September 2014 6:58:39 pm by Io Sol Inf

Sunday 07 September 2014 6:56:13 pm

Hello lo Sol Inf,

I don't know how your message could have been lost but I was wondering when you were going to reply happy.gif Emoticon

Lets just say I'm glad you posted again but i'm disapointed your still having problems, but then I did to.

I worked on the static cache configuration problem yesterday for well over 3 hours of setup, debug and testing.

Here is a gist with the configuration file that works for me, I'll explain it next.

I have posted my complete full staticcache.ini.append.php file as a gist from here: https://gist.github.com/brookinsconsulting/9a38194fce79a7c353ca

First off in staticcache.ini.append.php you must read the comments! They clearly state that the 'HostName' ini variable use is deprecated and should not be used.

That means to work you want to empty the variable like in my example above which will solve the error log entries you've been noticing (good catch my friend)!

Second, I have changed my .htaccess and staticcache.ini.append.php configuration to store and serve the static cache from within the var directory ... you should too! The reason for this is that static cache is just another type of cache and we in ezp store caches in the var directory not the site root, so change the 'StaticStorageDir' varaible as well to match my example.

Third, you should populate the CachedURLArray[] ini setting with as many content object urls as possible / desired to be cached with static html, if you don't put anything in this setting no content will be generated for the static cache.

And lastly, no you do not need to setup anything else like a fake host+port to generate the static content.

One thing to remember, the makestaticcache.php script uses curl to access your site and store the static copies of your site's page content. If you can not use curl from the ssh command line to access your site directly (some servers can't, like the current host of ezecossytem.org, we get a new thinkcreative host next week!!) then you will not be able to use the static cache feature.

I hope this helps...

Cheers,
Heath

Sunday 07 September 2014 7:22:47 pm

Quote from Io Sol Inf :

Edited: After a few more tests I was able to verify that the URl being fetched was http://<[CacheSettings]HostName>/<Actual URl of the page>.

If I set [CacheSettings]HostName to a nothing, the static cache is properly set, that seemed totally wrong, but after reading this comment in the code, I am not so sure...

Do I need to setup a fake host+port to generate the static content?

Hello lo Sol Inf,

I saw your forum message edit!

Here is a detailed description of why the Hostname ini setting variable was deprecated:

https://github.com/ezsystems/ezpublish-legacy/blob/master/settings/staticcache.ini#L12

The next line is the most explanatory: "Hostname is read from site.ini.[SiteSettings].SiteURL per siteaccess" in versions of ezp 4.4+

Today we are many many versions past ezp 4.4 so it makes sense that this ini variable must be blank in order for static cache to work. See ... in the past some people would not set the website hostname in site.ini.[SiteSettings].SiteURL per siteaccess and as such a different variable was used instead or at least that is my misguided interpretation based on what I've seen over the years of doing eZ Publish development.

I hope this helps ...

Cheers,
Heath

Monday 08 September 2014 12:52:47 am

Hi Heath

It really helps. Thanks a lot.

I might have run into a small bug now. The ↴ (arrow) besides the language selector shows as an ugly character in the static cache. It might be caused by encoding used in curl request or something related to it. I'll try to investigate and fix it before pushing the site to live. I'll update here (and create a jira) if I unveil anything

Again, many many thanks for all the assistance and care.

Cheers,
Io

Monday 08 September 2014 3:22:50 am

Hello lo Sol Inf,

I'm happy to be able to help you happy.gif Emoticon

I've heard of this utf8 content problem before, though I did not run into it during my own testing of the static cache feature this time.

Back in 2007 I setup static cache for a large manufacturer's product info site and they had utf8 problems with the static cache output at first but for the life of me I can't remember what the exact problem was. IE: web server, database (I think it was db related at first glance but so long ago I can't really remember), etc.

Here is one suggestion for you to try out.

Edit your apache virtual host configuration and add:

AddDefaultCharset  utf-8

Restart apache and manually remove all the static cache with rm -vrf, then recreate the static cache and test again.

From: http://share.ez.no/forums/install-configuration/static-cache-problem-with-character-encoding/comment9010

Another thread gave the more database content / client connection specific suggestion to run an additional query like this:

$db->query('SET CHARACTER SET utf8;');

From: http://share.ez.no/forums/install-configuration/no-matter-what-i-can-t-get-static-cache-to-work#comment6303

EDIT: On second thought I would recommend against the above db related kernel hack idea. Ideally the mysql database client connection should be correctly configured via standard mysql configuration settings (my.cnf). Re:  http://dev.mysql.com/doc/refman/5.7/en/charset-applications.html

Re: http://blackbe.lt/setting-up-utf-8-encoding-in-php-and-mysql/

Sorry I don't have a definitive response to your most recent problem. The truth is more information is needed because the problem could exist on several different levels.

Remember to report back to us if you have any more questions or if you find a suitable solution to your problem.

Cheers,
Heath

Modified on Monday 08 September 2014 5:30:38 am by // Heath

Wednesday 10 September 2014 11:47:39 am

Hi Heath

Please forgive me for the delay in my reply.

Since I am using a single installation for multiple sites, I had to tweak the rewrite rules a bit (I only intend to use static cache in one of the sites, for the time being).

I would like to thank you, once more, for all your care and insight. I am marking this topic as solved.

Cheers and many thanks

Io

Wednesday 10 September 2014 10:53:55 pm

Hello lo Sol Inf,

No worries on your delay in replying back.

I have to say thank you for the reply, I was wondering how things worked out for you.

* Did you solve your utf8 static cache problems? If so ... what did you do that fixed them?

Thank you for marking this thread as solved.

Your very welcome. It was a pleasure to help you out.

Cheers,
Heath 

Thursday 11 September 2014 12:09:39 am

Quote from // Heath :

* Did you solve your utf8 static cache problems? If so ... what did you do that fixed them?

Hi again.

Adding

AddDefaultCharset UTF-8

into the .htaccess was enough to solve the issue with the utf8. Now the makestaticcache script produces properly encoded files

Cheers,
Io

Sunday 21 September 2014 8:12:49 pm

Hello Again,

I thought I would add a brief note here for people looking for standard, tested, working mod_rewrite rules for an apache / httpd virtual host configuration file.

Use these rules as an example in your website's virtual host configuration file to enable and use static cache by default. https://gist.github.com/brookinsconsulting/a7aecefce2f676979634

 

Pro Tip: You can test a site and avoid the static cache by using url manipulation.

Simply enter your url in the browser and append /(offset)/0 text string to the url and load the page to access the standard eZ Publish page bypassing the static cache.

This works because the static cache feature by default does not cache requests using view parameters.

I hope this helps others!

Cheers,
Heath 

Modified on Sunday 21 September 2014 8:17:30 pm by // Heath

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from