support subdirectory Drupal installations

Asif99 - December 3, 2006 - 19:33
Project:Boost
Version:6.x-1.0-alpha4
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:duplicate
Description

Boost not working if drupal is installed in a directory. (eg. xyz.com/drupal)
Is there any workaround for this?

#1

Arto - December 3, 2006 - 19:50
Title:no support for drupal in directory» Doesn't work with subdirectory Drupal installation
Assigned to:Anonymous» Arto

Asif, please describe your problem - that is, in what way it doesn't work - in a bit more detailed fashion.

I don't off-hand know any reason why Boost wouldn't work in a subdirectory if Drupal's clean URLs do (meaning you've set your RewriteBase directive in the .htaccess

#2

Arto - December 3, 2006 - 19:51

Oops, the text got cut off... what I meant to say:

I don't off-hand know any reason why Boost wouldn't work in a subdirectory if Drupal's clean URLs do (meaning you've set your RewriteBase directive in the .htaccess file, etc.)

Of course, there may certainly a bug in the code that would prevent it - I don't have any Drupal installations in subdirectories so I haven't tested Boost with that.

#3

Asif99 - December 4, 2006 - 06:03

I have installed drupal in a subdirectory and it is working fine with clean urls and rewritebase. I installed boost and its not working. (no boost stamp in html). Although cache files are being created in cache directory.

Then for testing I created a Virtual Server in apache with drupal directory as Document Root. And removed 'RewriteBase /jauhar' from .htaccess. Boost is now working!

#4

Asif99 - December 4, 2006 - 06:20

found the problem in boosted.txt (.htaccess)

RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}/0/%{REQUEST_URI} -d
RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}/0/%{REQUEST_URI}/index.html -f
RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}/0/%{REQUEST_URI}.html -f

DOCUMENT_ROOT does not have any cache directory! cache directory is inside drupal. Changing these to following seems to be working.

RewriteCond %{DOCUMENT_ROOT}/drupal/cache/%{HTTP_HOST}/0/%{REQUEST_URI} -d
RewriteCond %{DOCUMENT_ROOT}/drupal/cache/%{HTTP_HOST}/0/%{REQUEST_URI}/index.html -f
RewriteCond %{DOCUMENT_ROOT}/drupal/cache/%{HTTP_HOST}/0/%{REQUEST_URI}.html -f

What should be the best solution for this?

#5

Asif99 - December 4, 2006 - 06:29

well, above is also not working.. I type the wrong url for testing... :(

#6

Arto - December 4, 2006 - 11:42

The best thing would be if you can attempt this on a server where you have access to change the RewriteLog level, so that you can get debug output and quickly find out what the problem is.

Looking at your rewrite rules, my hunch at the moment is that the %{REQUEST_URI} in the RewriteCond statements includes the /drupal prefix, so the files are being looked for in drupal/cache/hostname/0/drupal/page.html, when in actuality the file is written out by Boost as drupal/cache/hostname/0/page.html (note the missing drupal directory in there). If so, that is a bug and needs to be corrected in the code, after which your modified rewrite rules should work.

As I don't have a whole lot of time at present to tackle this, could you please verify that this indeed the cause of the problem; that is, if you manually create the drupal directory under the drupal/cache/hostname/0 directory, and move all the generated files into it, does caching work with your modified .htaccess rules?

#7

Asif99 - December 13, 2006 - 12:31

I enabled RewriteLogLevel, but it is not generating any logs under subdirectory drupal installation. (tail -f /var/log/httpd/rewrite_log |grep cache)

It does creates host folder, 0 and html pages correctly, but not able to use these for displaying. Any other suggestions?

#8

Arto - August 6, 2007 - 17:09

From recent comments by Justin Miller I think Boost still has this bug. Hunting down the bug is not a high priority for me at present, but I'll probably eventually get around to it. A patch to fix it sooner is welcome, of course.

#9

brush@groups.dr... - September 3, 2007 - 08:16

the following is a hack that is currently working for me (knock on wood), and could be used to make a proper general fix.

note: "drupal" should be replaced with appropriate subdir.

  RewriteCond %{REQUEST_METHOD} ^GET$
# Add subdir here:
  RewriteCond %{REQUEST_URI} ^/drupal/$
  RewriteCond %{QUERY_STRING} ^$
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
# Add subdir here:
  RewriteCond %{DOCUMENT_ROOT}/drupal/cache/%{SERVER_NAME}/0/index.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0/index.html [L]

  RewriteCond %{REQUEST_METHOD} ^GET$
# Add the following line:
  RewriteCond %{REQUEST_URI} ^(/drupal)(.*)$
# Change %{REQUEST_URI} to %2 in following 3 lines:
  RewriteCond %2 !^/cache
  RewriteCond %2 !^/user/login
  RewriteCond %2 !^/admin
# I'm not sure why, but the following line needed to be edited as follows to avoid screwing the %2:
  RewriteCond %{QUERY_STRING} !^.
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
# Change %{REQUEST_URI} to %2 in following 2 lines:
  RewriteCond %{DOCUMENT_ROOT}/share/cache/%{SERVER_NAME}/0%2 -d
  RewriteCond %{DOCUMENT_ROOT}/share/cache/%{SERVER_NAME}/0%2/index.html -f
# And change $1 to %2 in this line:
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0%2/index.html [R,L]
 
  RewriteCond %{REQUEST_METHOD} ^GET$
# Add the following line:
  RewriteCond %{REQUEST_URI} ^(/share)(.*)$
# Change %{REQUEST_URI} to %2 in following 3 lines:
  RewriteCond %2 !^/cache
  RewriteCond %2 !^/user/login
  RewriteCond %2 !^/admin
# I'm not sure why, but the following line needed to be edited as follows to avoid screwing the %2:
RewriteCond %{QUERY_STRING} !^.+
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
# Change %{REQUEST_URI} to %2 in following line:
  RewriteCond %{DOCUMENT_ROOT}/share/cache/%{SERVER_NAME}/0%2.html -f
# And change $1 to %2 in this line:
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0%2.html [L]

order matters.

hth,
.brush

#10

Liam McDermott - January 5, 2008 - 18:21

Just thought I'd confirm this bug. Am using the 5 stable branch (assuming as the htaccess has not changed between this and the dev branch that the bug is in both). The static files are created correctly, but not served. Am using a RewriteBase statement to point Apache at a subdirectory.

#11

Boringo - January 6, 2008 - 00:24

Thanks .brush for the code, I had to replace "/share" to "/drupal" in a few lines of your code and the system finally worked perfectly in a subdirectory named drupal.

#12

Mixel Adm - May 7, 2008 - 19:25

hi everybody
i just installed boost in a site under a subdirectory and i don't see any complication on it.

i see you use some replaces bud i didn't make any raplacemnt. the only thing you need to do is uncomment the line with the text
# RewriteBase /drupal

and write your subdirectoory like this

RewriteBase /agregador/

look that theres is a / at the end.

and magic happens....

Mixel Adm

#13

dadesigners - May 21, 2008 - 18:23

Hi Asif,
Please email me your contact info at info@dadesigners.com - i would like to speak with you.
Hope to hear from you soon.
Danish

#14

gdtechindia - June 23, 2008 - 19:16

i tried all the options, but boost didnt work in sub directory for me.

#15

drupdrips - September 11, 2008 - 05:49

It should work. I don't know about Apache, but in lighttpd, I have physical docroot of mydomain.com pointing to /var/www/public_html/mydomain.com . Drupal is installed at : /opt/drupal5

I have created a "cache" folder under "/var/www/public_html/mydomain.com" that soft links to cache folder under /opt/drupal5. /var/www/public_html/mydomain.com/cache -> /opt/drupal5/cache

In lighttpd.conf I have server.document-root pointing to : /var/www/public_html/mydomain.com

In lighttpd / lua rules for rewrite conditions : I made sure physical path gets picked up relative to physical docroot, which is how it should be anyway. Again, similar to Apache here, just that I have re-worked apache rules for lighttpd.

There is ONE bug that I found for which I had to resort to the option of softlinking as I mentioned in para 2.

That is this: Boost was creating cached files for me in web docroot and also lighttpd rules (I made sure) was picking up from the right place relative to docroot. However, page expiry was NOT happening. This is because boost_cache_directory is using cwd (current working directory) to arrive at the cache location which is working a little erratic (I did not choose to troubleshoot further as I found a easy quick solution). Basically cwd was switching between webserver docroot location as cwd and drupal base install as cwd directory. It was using docroot for creating cached files. But it was looking for drupal base install directory when trying to expire pages. So pages were not expiring for me. The quick solution was the softlink of "cache" subdirectory so it would find the path either way and use only one location.

#16

Arto - October 25, 2008 - 13:56
Component:Miscellaneous» Installation
Status:active» postponed (maintainer needs more info)

I will not be supporting the 4.7.x version any longer, but if somebody wants to roll up a proper patch and get some reviews and testers on it, I will certainly commit it to CVS. It would be a useful feature to have and should probably get forward-ported to 5.x and 6.x, if and when somebody does take the time to get this closed out.

#17

Arto - October 25, 2008 - 14:19
Assigned to:Arto» Anonymous

Unassigning myself as I don't intend to work on this just now. Anyone interested in seeing this work should feel free to tackle it.

#18

drupdrips - October 28, 2008 - 04:10

Hi Arto,

with soft linking between the cache folder from docroot and cache folder under drupal base install (wherever the directory maybe .. doesn't matter) this is no longer a problem. Maybe you can include a point in the usage guideline.

BTW Thanks for a great module with a real kick a$$ benefit.

#19

gingerjoos - November 12, 2008 - 06:16

workarounds/fixes mentioned in #18, #12 didn't work for me. Workaround mentioned in #9 seemed to work, once the fix mentioned in #11 was applied. Thanks a bunch guys :)

#20

giorgio79 - November 28, 2008 - 20:04

#9, #11 work for me only for the front page, the other pages are saved but not retrieved.

#18, #12 did not work for me unfortunately...

#21

andreiashu - December 3, 2008 - 23:20
Version:4.7.x-1.x-dev» 6.x-1.0-alpha1
Component:Installation» Code

I think that the problem comes from the boost_cache_set function too. More specifically the way we get the path aliases. My drupal installation is also in a subdir. Al least for me the REQUEST_URI var looks like this: /subdir/path_alias (i already have a "RewriteBase /subdir" in the .htaccess). Tthat means that we must include the subdir in the boost_cache_set too. So in the boost_cache_set function replace:

$alias = drupal_get_path_alias($path);
$path = drupal_get_normal_path($path); // normalize path

with this
$base_path = base_path() != '/' ? base_path() : '';
$alias = $base_path . drupal_get_path_alias($path);
$path = $base_path . drupal_get_normal_path($path); // normalize path

This if for the 6.x-1.0-alpha1 version. For me it worked flawlessly (until now).
Also for those of you who have a multilanguage site please have a look at: #342323: boost_cache_set not getting the correct url alias
Please try to test this and tell me if it makes sense what is said here.
Thanks

#22

develCuy - December 25, 2008 - 07:09

I have hacked it for Drupal 5:

1. .htaccess

# BOOST START
  <IfModule mod_headers.c>
    Header add Expires "Sun, 19 Nov 1978 05:00:00 GMT"
    Header add Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
  </IfModule>
  <IfModule mod_mime.c>
    AddCharset utf-8 .html
  </IfModule>
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} ^/$
  RewriteCond %{QUERY_STRING} ^$
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{DOCUMENT_ROOT}drupal/cache/%{SERVER_NAME}/0/index.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0/index.html [L]
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} !^/cache
  RewriteCond %{REQUEST_URI} !^/user/login
  RewriteCond %{REQUEST_URI} !^/admin
  RewriteCond %{QUERY_STRING} ^$
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{DOCUMENT_ROOT}drupal/cache/%{SERVER_NAME}/0%{REQUEST_URI} -d
  RewriteCond %{DOCUMENT_ROOT}drupal/cache/%{SERVER_NAME}/0%{REQUEST_URI}/index.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0/$1/index.html [L]
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} !^/cache
  RewriteCond %{REQUEST_URI} !^/user/login
  RewriteCond %{REQUEST_URI} !^/admin
  RewriteCond %{QUERY_STRING} ^$
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{DOCUMENT_ROOT}drupal/cache/%{SERVER_NAME}/0%{REQUEST_URI}.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0/%{REQUEST_URI}.html [L]
  # BOOST END

Notice: I'm using 'drupal' instead of '/drupal'

2. boost.api.inc

  // Execute the pre-process function if one has been defined
  if (function_exists(BOOST_PRE_PROCESS_FUNCTION))
    $data = call_user_func(BOOST_PRE_PROCESS_FUNCTION, $data);

  global $base_path;
  $bpath = $base_path != '/' ? substr($base_path, 1) : $base_path;
  $alias = $bpath . drupal_get_path_alias($path);
  $path = drupal_get_normal_path($path); // normalize path

Blessings!

#23

Gerhard Killesreiter - April 20, 2009 - 09:42
Version:6.x-1.0-alpha1» 6.x-1.x-dev

I am using boost on a multisite install where the individual sites are "subdirectories" of the main site. The subdirectories are actually fakes creates by symlinks back to the main install.

I've modified boost to work for this use case.

The only modification I needed in boost itself was in boost_cache_directory:

original:

  return implode('/', !$absolute ? array('cache', $host) : array(getcwd(), 'cache', $host));

modified:

  return implode('/', !$absolute ? array('cache', $host, $parts['path']) : array(getcwd(), 'cache', $host, $parts['path']));

Maybe more is needed, not sure, it seems to work.

The modifications in .htaccess are a bit more extensive. The problem is that mod_rewrite tries to be helpful and strips the subdirectory from the path. The solution I found was to add that subdirectory into an environment variable. This needs to be done in the main vhost config:

RewriteCond %{REQUEST_URI} ^/([^/]+)/(.*)$
RewriteRule ^([^.]+)$  - [E=INFO_REQUEST_URI:%1,NE]

The .htacess code then looks like this:

 
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} ^/$
  RewriteCond %{QUERY_STRING} ^$
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
#  RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}/0/index.html -f
  RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}/%{ENV:INFO_REQUEST_URI}/0/index.html -f
#  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0/index.html [L]
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/%{ENV:INFO_REQUEST_URI}/0/index.html [L]
 
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} !^/cache
  RewriteCond %{REQUEST_URI} !^/user/login
  RewriteCond %{REQUEST_URI} !^/admin
  RewriteCond %{QUERY_STRING} ^$
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
#  RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}/0%{REQUEST_URI} -d
  RewriteCond %{DOCUMENT_ROOT}cache/%{SERVER_NAME}/%{ENV:INFO_REQUEST_URI}/0/$1 -d
#  RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}/0%{REQUEST_URI}/index.html -f
  RewriteCond %{DOCUMENT_ROOT}cache/%{SERVER_NAME}/%{ENV:INFO_REQUEST_URI}/0/$1/index.html -f
#  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0/$1/index.html [L]
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/%{ENV:INFO_REQUEST_URI}/0/$1/index.html [L]

  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} !^/cache
  RewriteCond %{REQUEST_URI} !^/user/login
  RewriteCond %{REQUEST_URI} !^/admin
  RewriteCond %{QUERY_STRING} ^$
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
#  RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}/0%{REQUEST_URI}.html -f
  RewriteCond %{DOCUMENT_ROOT}cache/%{SERVER_NAME}/%{ENV:INFO_REQUEST_URI}/0/$1.html -f
#  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/0/$1.html [L]
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/%{ENV:INFO_REQUEST_URI}/0/$1.html [L]
# BOOST END

#24

rsvelko - April 20, 2009 - 14:45

@Gerhard Killesreiter: give more detail on the places of the dirs you use - which is where and links to what - examples? I can give advice on the best practice and I have done the same inthe past.

nice to know about the env vars in apache - may be useful in a curent feature request with moving cache dir to sites/example.com/html_cache ...

#25

mikeytown2 - April 20, 2009 - 22:00

If the above rules could be generalized so they work on single & multi; shared & VPS; apache 1.3+; root & subdir that would be amazing. For the php something like

<?php
if (empty($parts['path'])) {
  return
implode('/', !$absolute ? array('cache', $host) : array(getcwd(), 'cache', $host));
}
else {
  return
implode('/', !$absolute ? array('cache', $host, $parts['path']) : array(getcwd(), 'cache', $host, $parts['path']));
}
?>

Apache would require something like this ?

SetEnv INFO_REQUEST_URI /subdir

http://httpd.apache.org/docs/1.3/mod/mod_env.html
http://httpd.apache.org/docs/2.0/mod/mod_env.html
I think it can be set in the .htaccess file in 1.3

How deep does the subdir work with this rule?

RewriteCond %{REQUEST_URI} ^/([^/]+)/(.*)$
RewriteRule ^([^.]+)$  - [E=INFO_REQUEST_URI:%1,NE]

example.com/my/deep/sub/dir would need to work, in order for this to be added to the main branch of boost.

#26

Gerhard Killesreiter - April 27, 2009 - 12:59

@rsvelko: Don't think I need advice there, it works after all. But thanks.

@mikeytown2: the rewrite condition looks at the requested file path and stores the first part in the variable. This relies on the fact that I already know that the first part is the subdirectory I want. Would my install be two directories deep I would need to modify the regexp.

I am not sure this can or should be added to the main code. Maybe as some extended docs?

#27

mikeytown2 - April 27, 2009 - 20:58
Status:postponed (maintainer needs more info)» postponed

I'm leaning towards php generated htaccess rules that you then copy/paste in. That would keep the rewrite rules fairly simple and still allow for many different installation profiles. I think there's enough info here to do a subdir install & possibly a multi site install. The php would generate some hard coded settings to make the rewrite rule generation easier.

#28

mikeytown2 - May 3, 2009 - 02:29
Version:6.x-1.x-dev» 6.x-1.0-alpha4
Status:postponed» active

Here's some rules for 6.x-1.0-alpha4 & for a subdir install. Replace DRUPAL-SUBDIR with your subdir. Based off of #9 above.

  # BOOST START
  <IfModule mod_headers.c>
    Header add Expires "Sun, 19 Nov 1978 05:00:00 GMT"
    Header add Cache-Control "store, no-cache, must-revalidate, post-check=0, pre-check=0"
  </IfModule>
  <IfModule mod_mime.c>
    AddCharset utf-8 .html
  </IfModule>
  <FilesMatch "\.(html.gz)$">
    AddEncoding x-gzip .gz
    ForceType text/html
  </FilesMatch>
  #serve file IF it exist on server
  RewriteCond %{REQUEST_FILENAME} -f
  RewriteRule .? - [L]
 
  #GZIP
  # root
  RewriteCond %{REQUEST_METHOD} ^GET$   
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(/)$
  RewriteCond %{QUERY_STRING} ![\=]+
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/gz/%{SERVER_NAME}/index.html.gz -f
  RewriteRule ^(.*)$ cache/gz/%{HTTP_HOST}/index.html.gz [L]
  # subdir root
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(.*)$
  RewriteCond %2 !(^/admin|^/cache|^/misc|^/modules|^/sites|^/system|^/themes|^/user/login)
  RewriteCond %{QUERY_STRING} ![\=]+
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/gz/%{SERVER_NAME}%2 -d
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/gz/%{SERVER_NAME}%2/index.html.gz -f
  RewriteRule ^(.*)$ cache/gz/%{SERVER_NAME}%2/index.html.gz [L]
  # non root
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(.*)$
  RewriteCond %2 !(^/admin|^/cache|^/misc|^/modules|^/sites|^/system|^/themes|^/user/login)
  RewriteCond %{QUERY_STRING} ![\=]+
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/gz/%{SERVER_NAME}/%2.html.gz -f
  RewriteRule ^(.*)$ cache/gz/%{SERVER_NAME}%2.html [L]
  # url variables
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(.*)$
  RewriteCond %2 !(^/admin|^/cache|^/misc|^/modules|^/sites|^/system|^/themes|^/user/login)
  RewriteCond %{QUERY_STRING} !^$
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/gz/%{SERVER_NAME}%2_%{QUERY_STRING}.html.gz -f
  RewriteRule ^(.*)$ cache/gz/%{SERVER_NAME}%2_%{QUERY_STRING}.html.gz [L]
 
  #NORMAL
  # root
  RewriteCond %{REQUEST_METHOD} ^GET$   
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(/)$
  RewriteCond %{QUERY_STRING} ![\=]+
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/%{SERVER_NAME}/index.html -f
  RewriteRule ^(.*)$ cache/%{HTTP_HOST}/index.html [L]
  # subdir root
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(.*)$
  RewriteCond %2 !(^/admin|^/cache|^/misc|^/modules|^/sites|^/system|^/themes|^/user/login)
  RewriteCond %{QUERY_STRING} ![\=]+
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/%{SERVER_NAME}%2 -d
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/%{SERVER_NAME}%2/index.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}%2/index.html [L]
  # non root
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(.*)$
  RewriteCond %2 !(^/admin|^/cache|^/misc|^/modules|^/sites|^/system|^/themes|^/user/login)
  RewriteCond %{QUERY_STRING} ![\=]+
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/%{SERVER_NAME}/%2.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}%2.html [L]
  # url variables
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(.*)$
  RewriteCond %2 !(^/admin|^/cache|^/misc|^/modules|^/sites|^/system|^/themes|^/user/login)
  RewriteCond %{QUERY_STRING} !^$
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/%{SERVER_NAME}%2_%{QUERY_STRING}.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}%2_%{QUERY_STRING}.html [L]
  # BOOST END

#29

mikeytown2 - May 3, 2009 - 03:12
Status:active» needs review

For some reason gzip messes up here. This should work for a subdirectory Drupal installation, but only gzip support for the front page.

  # BOOST START
  <IfModule mod_headers.c>
    Header add Expires "Sun, 19 Nov 1978 05:00:00 GMT"
    Header add Cache-Control "store, no-cache, must-revalidate, post-check=0, pre-check=0"
  </IfModule>
  <IfModule mod_mime.c>
    AddCharset utf-8 .html
  </IfModule>
  <FilesMatch "\.(html.gz)$">
    AddEncoding x-gzip .gz
    ForceType text/html
  </FilesMatch>
  #serve file IF it exist on server
  RewriteCond %{REQUEST_FILENAME} -f
  RewriteRule .? - [L]

  #GZIP
  # root
  RewriteCond %{REQUEST_METHOD} ^GET$  
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(/)$
  RewriteCond %{QUERY_STRING} ![\=]+
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/gz/%{SERVER_NAME}/index.html.gz -f
  RewriteRule ^(.*)$ cache/gz/%{HTTP_HOST}/index.html.gz [L]

  #NORMAL
  # root
  RewriteCond %{REQUEST_METHOD} ^GET$  
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(/)$
  RewriteCond %{QUERY_STRING} ![\=]+
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/%{SERVER_NAME}/index.html -f
  RewriteRule ^(.*)$ cache/%{HTTP_HOST}/index.html [L]
  # subdir root
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(.*)$
  RewriteCond %2 !(^/admin|^/cache|^/misc|^/modules|^/sites|^/system|^/themes|^/user/login)
  RewriteCond %{QUERY_STRING} ![\=]+
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/%{SERVER_NAME}%2 -d
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/%{SERVER_NAME}%2/index.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}%2/index.html [L]
  # non root
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(.*)$
  RewriteCond %2 !(^/admin|^/cache|^/misc|^/modules|^/sites|^/system|^/themes|^/user/login)
  RewriteCond %{QUERY_STRING} ![\=]+
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/%{SERVER_NAME}/%2.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}%2.html [L]
  # url variables
  RewriteCond %{REQUEST_METHOD} ^GET$
  RewriteCond %{REQUEST_URI} ^(/DRUPAL-SUBDIR)(.*)$
  RewriteCond %2 !(^/admin|^/cache|^/misc|^/modules|^/sites|^/system|^/themes|^/user/login)
  RewriteCond %{QUERY_STRING} !^$
  RewriteCond %{HTTP_COOKIE} !DRUPAL_UID
  RewriteCond %{DOCUMENT_ROOT}/DRUPAL-SUBDIR/cache/%{SERVER_NAME}%2_%{QUERY_STRING}.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}%2_%{QUERY_STRING}.html [L]
  # BOOST END

#30

marcingy - May 9, 2009 - 21:55

Just tried it on development server with drupal in a subdir and it seems to work well. Thanks for the fix.

#31

toolman - May 11, 2009 - 16:48

The solution in #29 may not work depending on your site configuration.
If your DRUPAL-SUBDIR is not under %{DOCUMENT_ROOT} usually /var/www the cache folder is not found.
You have to replace %{DOCUMENT_ROOT}/DRUPAL-SUBDIR with the absolute path on your server e.g. /home/www/drupal.

#32

didacticus - May 12, 2009 - 20:28

#29 is working well for me. Thanks mikeytown2!

#33

mikeytown2 - May 17, 2009 - 18:45
Status:needs review» reviewed & tested by the community

This will stay at RTBTC until #428942: AHAH update textarea for .htaccess rules on performance page. is done

#34

Drupal_is_amazing - May 21, 2009 - 09:01

so, does gzipping currently only work for the root, as of this moment? I've done lots of fiddling with various rewrite rules, but can't seem to get it to work for the majority of pages on my site.

Which raises another issue-- how do I know _if_ it is working. I've been using firebug to see the size of the incoming files, but I don't know that actually works. Perhaps adding another banner to the file before gzipping it would allow us to look at the source and see whether we're being served live, normal cache, or gzipped cache. Or is there already an easy way to determine which is which?

#35

mikeytown2 - May 21, 2009 - 09:23

@Drupal_is_amazing
My other project has a good explanation for checking gzip: http://drupal.org/project/css_gzip

The YSlow Firefox add-on has a tab called components; you can check for gzip compression there. See YSlow User Guide -> Components View.

Gzip for subdirs only works for root ATM. I have some creative ideas on how to make it work #276495: Update for Rewrite Rules - Give Boost even bigger performance gain, but its a low priority; boost needs a lot of help still in other areas.

#36

Drupal_is_amazing - May 21, 2009 - 10:39

Yeah, I imagine it's less of a priority for my site than for most-- my site is very text intensive, so gzip seems to cut my bandwidth in half. For a site that was more photo based, the gzip probably wouldn't offer as substantial a benefit.

Thanks so much for all the great work your doing on this. You're a lifesaver.

#37

mikeytown2 - May 24, 2009 - 08:54
Title:Doesn't work with subdirectory Drupal installation» support subdirectory Drupal installations
Category:bug report» feature request

Renaming title to better match current state of this issue

#38

mikeytown2 - May 26, 2009 - 01:44

Give this a shot, should do gzip in subdirs.

  # BOOST START
  <FilesMatch "\.(html.gz|html)$">
    <IfModule mod_headers.c>
      Header set Expires "Sun, 19 Nov 1978 05:00:00 GMT"
      Header set Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
    </IfModule>
  </FilesMatch>
  <IfModule mod_mime.c>
    AddCharset utf-8 .html
  </IfModule>
  <FilesMatch "\.(html.gz)$">
    AddEncoding x-gzip .gz
    ForceType text/html
  </FilesMatch>
  #serve file IF it exist on server
  RewriteCond %{REQUEST_FILENAME} \.\w{2,4}$
  RewriteCond %{REQUEST_FILENAME} -f
  RewriteRule .? - [L]
 
  #skip boost IF not get request OR uri has wrong dir OR cookie is set
  RewriteCond %{REQUEST_METHOD} !^GET$ [OR]
  RewriteCond %{REQUEST_URI} ^/april(/admin|/cache|/misc|/modules|/sites|/system|/themes|/user/login) [OR]
  RewriteCond %{HTTP_COOKIE} DRUPAL_UID
  RewriteRule .? - [S=11]
  #Skip Gzip section if it can't take gzip
  RewriteCond %{HTTP:Accept-encoding} !gzip
  RewriteRule .? - [S=5]

  #GZIP
  #Skip next 3 rules IF uri contains a query string
  RewriteCond %{QUERY_STRING} !^$
  RewriteRule .? - [S=3]

  # root
  RewriteCond %{REQUEST_URI} ^(/april)(/)$
  RewriteCond %{DOCUMENT_ROOT}/april/cache/gz/%{SERVER_NAME}/index.html.gz -f
  RewriteRule ^(.*)$ cache/gz/%{SERVER_NAME}/index.html.gz [L]
  # subdir root
  RewriteCond %{REQUEST_URI} ^(/april)(.*)$
  RewriteCond %{DOCUMENT_ROOT}/april/cache/gz/%{SERVER_NAME}%2 -d
  RewriteCond %{DOCUMENT_ROOT}/april/cache/gz/%{SERVER_NAME}%2/index.html.gz -f
  RewriteRule ^(.*)$ cache/gz/%{SERVER_NAME}%2/index.html.gz [L]
  # non root
  RewriteCond %{REQUEST_URI} ^(/april)(.*)$
  RewriteCond %{DOCUMENT_ROOT}/april/cache/gz/%{SERVER_NAME}/%2.html.gz -f
  RewriteRule ^(.*)$ cache/gz/%{SERVER_NAME}%2.html.gz [L]
  # url variables
  RewriteCond %{REQUEST_URI} ^(/april)(.*)$
  RewriteCond %{DOCUMENT_ROOT}/april/cache/gz/%{SERVER_NAME}%2_%{QUERY_STRING}.html.gz -f
  RewriteRule ^(.*)$ cache/gz/%{SERVER_NAME}%2_%{QUERY_STRING}.html.gz [L]
 
 
  #NORMAL
  #Skip next 3 rules IF uri contains a query string
  RewriteCond %{QUERY_STRING} !^$
  RewriteRule .? - [S=3]
 
  # root
  RewriteCond %{REQUEST_URI} ^(/april)(/)$
  RewriteCond %{DOCUMENT_ROOT}/april/cache/%{SERVER_NAME}/index.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}/index.html [L]
  # subdir root
  RewriteCond %{REQUEST_URI} ^(/april)(.*)$
  RewriteCond %{DOCUMENT_ROOT}/april/cache/%{SERVER_NAME}%2 -d
  RewriteCond %{DOCUMENT_ROOT}/april/cache/%{SERVER_NAME}%2/index.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}%2/index.html [L]
  # non root
  RewriteCond %{REQUEST_URI} ^(/april)(.*)$
  RewriteCond %{DOCUMENT_ROOT}/april/cache/%{SERVER_NAME}/%2.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}%2.html [L]
  # url variables
  RewriteCond %{REQUEST_URI} ^(/april)(.*)$
  RewriteCond %{DOCUMENT_ROOT}/april/cache/%{SERVER_NAME}%2_%{QUERY_STRING}.html -f
  RewriteRule ^(.*)$ cache/%{SERVER_NAME}%2_%{QUERY_STRING}.html [L]
  # BOOST END

EDIT: Replace april with your subdir name in the above code.

#39

mikeytown2 - May 26, 2009 - 05:55
Status:reviewed & tested by the community» duplicate

Moving to
#428942: AHAH update textarea for .htaccess rules on performance page.

#40

mikeytown2 - May 26, 2009 - 09:19

k... figured out the root cause of the majority of the headaches. The $path variable isn't the same when accessed from different routes in the code. boost_init() is to blame. This line needs to be added to it in order to correctly handle subdirs

<?php
  $GLOBALS
['_boost_path'] = ($base_path != '/') ? ltrim($base_path, '/') . $GLOBALS['_boost_path'] : $GLOBALS['_boost_path'];
?>

It adds on the $base_path to $GLOBALS['_boost_path']. $path from drupal has the $base_path already added to it. This will simply the rewrite a little bit more :) and make fixing some bugs simpler #443736: Smarter boost_cache_expire(). Path Changes & Wildcard Support.

I will add this code to the boost_init() rewrite patch #385924: Don't cache pages when there are PHP/MySQL errors and make the corresponding changes to the htaccess generation function.

 
 

Drupal is a registered trademark of Dries Buytaert.