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

Comments

Arto’s picture

Title: no support for drupal in directory » Doesn't work with subdirectory Drupal installation
Assigned: Unassigned » 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

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.

Arto’s picture

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.

Asif99’s picture

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!

Asif99’s picture

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?

Asif99’s picture

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

Arto’s picture

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?

Asif99’s picture

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?

Arto’s picture

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.

brush@groups.drupal.org’s picture

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

Liam McDermott’s picture

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.

Boringo’s picture

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.

Mixel Adm’s picture

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

DA Designers’s picture

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

gdtechindia’s picture

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

drupdrips’s picture

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.

Arto’s picture

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.

Arto’s picture

Assigned: Arto » Unassigned

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.

drupdrips’s picture

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.

gingerjoos’s picture

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 :)

giorgio79’s picture

#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...

andreiashu’s picture

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

develCuy’s picture

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!

Gerhard Killesreiter’s picture

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
rsvelko’s picture

@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 ...

mikeytown2’s picture

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

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.

Gerhard Killesreiter’s picture

@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?

mikeytown2’s picture

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.

mikeytown2’s picture

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
mikeytown2’s picture

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
marcingy’s picture

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

toolman’s picture

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.

no longer here 505822’s picture

#29 is working well for me. Thanks mikeytown2!

mikeytown2’s picture

Status: Needs review » Reviewed & tested by the community
Drupal_is_amazing’s picture

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?

mikeytown2’s picture

@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.

Drupal_is_amazing’s picture

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.

mikeytown2’s picture

Title: Doesn't work with subdirectory Drupal installation » support subdirectory Drupal installations
Category: bug » feature

Renaming title to better match current state of this issue

mikeytown2’s picture

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.

mikeytown2’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
mikeytown2’s picture

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

  $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.

mikeytown2’s picture

Version: 6.x-1.0-alpha4 » 5.x-1.x-dev
Status: Closed (duplicate) » Needs review

reopen for 5.x #22

mikeytown2’s picture

Status: Needs review » Closed (fixed)

Closing all 5.x issues; will only reevaluate if someone steps up #454652: Looking for a co-maintainer - 5.x

Reason is 6.x has 10x as many users as 5.x; also last 5.x dev was over a year ago. The 5.x issue queue needs to go.

mclinn’s picture

Adding my two cents (and gratitude) here. Same thing, version 5, drupal in a subdirectory, no luck with Boost. Created cached files but wouldn't retrieve them.

Comments #9 and #11 worked for me. I also had to change the RewriteBase parameter to match my subdirectory, also added a default charset to utf-8 directive to stop high ascii characters from showing up. And I will probably force all requests to "non-www" format to avoid that ambiguity.

The performance difference is amazing. There are still some odd permission things going on but I think I can deal with them. My site is almost all anon. users so will benefit greatly from this module. I plan to investigate "pre-caching" also, maybe doing wget on the xml file from xml sitemap or something similar. And one day when I feel nervy I'll upgrade to version 6 (or maybe 7?) and use the newer features.

Thanks to everybody involved for such a great module and all the efforts in helping it to work in the variety of ways we need it to!