I dream of a drush command that would backup and patch .htaccess (using the drupal core pretty urls at the end as an anchor to insert before)

And also for those that have modified their .htaccess prior to boost installation we should release just the boost rules in a file - not the whole .htaccess. I propose this to be the only form of distribution of the boost rewrite rules. Should be mentioned in .htaccess.

With a warning in INSTALL.txt for those who install to resolve any possible conflicts between pre-boost manual rules and boost rules...

If anyone knows of an include statement in .htaccess files let me know - thus it will be a matter of just inserting one line in the .htaccess that references a file in the boost module dir...

What do you think? Is a patch welcome?

PS I notriced that the (6.x.dev) boosted1.txt file is a little out of date with the 6.10 core .htaccess - which combined with my manual customizations made the idea appear.

Comments

mikeytown2’s picture

is there an example of this being done out there?

rsvelko’s picture

keeping it simple: for starters - lets just gather opinions: would you like a change in boost install process like that above?

The drush part is the last thing to be done.

@mikeytown2: you mean me attaching a patch ? this evening will try

mikeytown2’s picture

not adding a patch just yet; wondering if there is any example of a module checking & editing the root .htaccess file, and if that would be bad for security.

rsvelko’s picture

thought 10 mins about it : lets keep it simple :
- forget about auto-patching .htaccess via drush (at least until the install process for modules becomes more advanced - with custom pre/post install scripts and user prompts ...)
- leave only boost specific rules in the what are now boosted1.txt and the boosted2 (patch underway)
- patch install and/or readme to give proper info ...

seems trivial and a better way to install boost - are we/you into it?

mikeytown2’s picture

your proposal, short and simple: boosted(1/2).txt only has the

#BOOST START 
....
#BOOST END

in it. I think we could do something like that; but having the full .htaccess file is kinda nice, so we could make the default.txt file have a #Paste Boost Changes Here section. Update readme file to reflect changes. Is this what your thinking?

rsvelko’s picture

YES, with a little clarification:
- .htaccess is nice to have but it changes slightly with every new drupal core release - that is the main reason behind me dropping it
- maybe it will be easier and enough if we just say in the readme(or install):

"In the main .htaccess of your Drupal folder find the lines like these at the end and paste the contents of boosted1.txt BEFORE them :

[.htaccess file ]

...

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

# $Id: .htaccess,v 1.90.2.3 2008/12/10 20:04:08 goba Exp $

[end of file]

The result should look like :

[.htaccess file ]

...

#BOOST START
....
#BOOST END

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

# $Id: .htaccess,v 1.90.2.3 2008/12/10 20:04:08 goba Exp $

[end of file]

"

Seems ok to me. Maybe finding a shorter way to explain it will be good but not so important.

rsvelko’s picture

actually I have a smarter idea now:

why don't we just automate the

#BOOST START
....
#BOOST END

rules creation process via php(or js) and make these rules copy-pastable from the boost UI to the .htaccess file with checkboxes which rule set does the user want to see .

This makes sense cause the rules have 2-3 variants (boosted1.txt and boosted2.txt) and it would make things more user friendly.

mikeytown2’s picture

StatusFileSize
new14.06 KB

Here's a patch with the above changes (excluding change .htaccess via php) as well as these changes
http://drupal.org/node/204832#comment-1504968
This patch does not include replace $1 with %{REQUEST_URI} from that thread, just the simple changes.

___

mikeytown2’s picture

Status: Active » Needs review
mikeytown2’s picture

In terms of using php to modify the .htaccess file, Wordpress modifies the .htaccess file, so it is doable http://codex.wordpress.org/Using_Permalinks#Using_.22Pretty.22_permalinks. I'm thinking boost stores a md5 of the text in between #BOOST START & #BOOST END in the db. Use the update.php mechanism when a change to the Boosts .htaccess rules are needed.

Or use something like this
http://drupal.org/project/patchdoq

patataur’s picture

FWIW, i had no problem in adding the required lines in my htaccess but i believe for boost to have a wider implementation, it would require "automatic" htaccess modifications (many users just won't edit their htaccess i believe).

But, i think it is not a priority. First, a stable release. Then an easier installation of the module, rather than the reverse.

rsvelko’s picture

Lets keep it simple and safe - no modification of .htaccess via php .

Just creation of boost rules in the UI of boost in a fieldgroup and requiring the user to copy paste them...

mikeytown2’s picture

Status: Needs review » Needs work

I like the idea of the rules being inside the performance page, ready to be copied. Need to write the code for that...

mikeytown2’s picture

Title: Instead of overwriting .htaccess manually only add the boost rules in it » Generate .htaccess rules on performance page. Add checks for correct info inside .htaccess file.

I was thinking the easiest way to make sure people install the rule set correctly is to read the .htaccess file and throw a warning on the status page if the boost rules are not in there. This would check against the generated file, make sure they matched & is placed in the right spot (above index.php rule, below rewrite base).

mikeytown2’s picture

Committed the ideas from the top of this thread. Still open, since there are multiple issues in this one.

mikeytown2’s picture

Status: Needs work » Active
rsvelko’s picture

looked into the commits - very pleased.

What is left now is
1. the php code that will generate the rules in the UI to be pasted. (using a template file)
2. the code that will check the .htaccess file for the boost rules. Either checking strictly for the whole bunch of boost rules or just for the begin and end "# BOOST START" markers

Right?

mikeytown2’s picture

Odds are a template file is not needed; we need to make a function that generates the code, with most of the code being hard coded in. For the rules checking it would make sure the rules where put in the right spot (below # RewriteBase / and above # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.), and that there are at least 4 RewriteRule ^(.*)$ inside the Boost Start/End code block. On the status page, throw notices if the rules checking failed, linking to the handbook or something like that #443658: Boost Handbook Page(s). For the generation it should generate it for SERVER_NAME or HTTP_HOST and Normal or Subdir; only boost code, full .htaccess, unmodified .htaccess.

rsvelko’s picture

1. OK, please attach a text file with examples of all possible rules. I will take it and create the generating function. I leave the UI stuff to you (the page from which the user will paste the code).
2. I will make also the function that checks the .htaccess file for boost rules - you will take it and finish it to output status messages...

OK?

mikeytown2’s picture

StatusFileSize
new3.76 KB
new2.5 KB

Here are the 2 rules, the Gzip part has slightly changed based off this code
http://drupal.org/node/101227#comment-1597328
The bug doesn't effect html files.

Here are a list of things that should be changeable
cache/ OR User Defined
/DRUPAL-SUBDIR OR $base_path OR User Defined
gz/ OR User Defined
%{DOCUMENT_ROOT} OR getcwd() OR User Defined
%{HTTP_HOST} OR %{SERVER_NAME} OR User Defined

I don't have a multi-site setup so I can not test for it; so for now do it for normal & subdir. Also be aware that #276495: Update for Rewrite Rules - Give Boost even bigger performance gain if it ever gets done will change the rules again & make them shorter; it would eliminate the gzip subdir bug most likely as well.
#101147: support subdirectory Drupal installations

rsvelko’s picture

Ok, as soon as someone has some code - give it here so we can not do double work.

mikeytown2’s picture

StatusFileSize
new6.93 KB
mikeytown2’s picture

Status: Active » Needs review
rsvelko’s picture

StatusFileSize
new1.05 KB

Attaching the prototype of the checker function.

rsvelko’s picture

as for the review of #22 and #23 - looks ok. Can you summarize all the modes of boost operation:

----- group one - possible site setups -----
- single/multisite
- root of vhost/subdir
- gzip/no gzip
- $base_url set/ not set

----- group two - possible input vars:
- cache/ OR User Defined
- /DRUPAL-SUBDIR OR $base_path OR User Defined
- gz/ OR User Defined
- %{DOCUMENT_ROOT} OR getcwd() OR User Defined
- %{HTTP_HOST} OR %{SERVER_NAME} OR User Defined

Which of the possible permutations we are going to do? I am putting it all in one post here. Is $base_url set up in settings.php still a requirement?

mikeytown2’s picture

StatusFileSize
new3.88 KB

The last patch #367081: System-Ran Cron, Not User made it so cron will still work even if $base_url is not set; but it's not %100, which is why $base_url should be set.

Refactored the rules so it includes #276495: Update for Rewrite Rules - Give Boost even bigger performance gain and so normal/subdir look almost identical. Auto configures $base_path as well. Usage is fairly straight forward IMO, unless your not following the defaults or have some funky server settings, it should just work.

mikeytown2’s picture

StatusFileSize
new3.75 KB

Newest one based off of this revelation.

mikeytown2’s picture

StatusFileSize
new3.53 KB

further refinements & support for index url variables

mikeytown2’s picture

Came up with another idea to make the htaccess file smaller. Make query & normal files look the same; get rid of index. Inside boost_init() change

  // Make the proper filename for our query
  $fname = '';
  foreach ($_GET as $key => $val) {
    if ($key != 'q') {
      $fname .= (empty($fname) ? '' : '&') . $key . '=' . $val;
    }
  }
  //set variables
  global $user, $base_path;
  $GLOBALS['_boost_query'] = (empty($fname) ? '' : '_' . $fname);
  $GLOBALS['_boost_path'] = (empty($_REQUEST['q'])) ? 'index' : $_REQUEST['q'];
  $GLOBALS['_boost_path'] = ($base_path != '/') ? ltrim($base_path, '/') . $GLOBALS['_boost_path'] : $GLOBALS['_boost_path'];

to this

  global $user, $base_path;
  //set variables
  $GLOBALS['_boost_path'] = ($base_path != '/') ? ltrim($base_path, '/') . $_REQUEST['q'] : $_REQUEST['q'];
  // Make the proper filename for our query
  $GLOBALS['_boost_query'] = '_';
  foreach ($_GET as $key => $val) {
    if ($key != 'q') {
      $GLOBALS['_boost_query'] .= (($GLOBALS['_boost_query'] == '_') ? '' : '&') . $key . '=' . $val;
    }
  }

  # 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} ^(/admin|/cache|/misc|/modules|/sites|/system|/themes|/user/login) [OR]
  RewriteCond %{HTTP_COOKIE} DRUPAL_UID
  RewriteRule .* - [S=2]

  #GZIP
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{DOCUMENT_ROOT}/cache/gz/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}.html.gz -f
  RewriteRule .* cache/gz/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}.html.gz [L]

  #NORMAL
  RewriteCond %{DOCUMENT_ROOT}/cache/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}.html -f
  RewriteRule .* cache/%{SERVER_NAME}%{REQUEST_URI}_%{QUERY_STRING}.html [L]
  # BOOST END

It works. Thoughts??? Unless there are some good reasons to not do this, I will commit this as it makes the code simpler (boost block works with queries now).

mikeytown2’s picture

StatusFileSize
new1.63 KB

Here's a patch with more refinements.

mikeytown2’s picture

committed code from #29, along with corresponding changes to htaccess

mikeytown2’s picture

StatusFileSize
new3.19 KB

Patch generates htaccess rules inside settings page now.

mikeytown2’s picture

StatusFileSize
new2.68 KB

patch checks for rewrite rules, makes sure there are 4 of these strings in your .htaccess file.

%{REQUEST_URI}_%{QUERY_STRING}.html
mikeytown2’s picture

Status: Needs review » Fixed

committed 32, 33

mikeytown2’s picture

Status: Fixed » Needs work

Need to use AHAH and add in some selection tools so user can generate different .htaccess code from interface.

mikeytown2’s picture

Title: Generate .htaccess rules on performance page. Add checks for correct info inside .htaccess file. » Generation of .htaccess rules on performance page.
Status: Needs work » Needs review
StatusFileSize
new4.61 KB

Allows for selection of rules; using -s instead of -f (checks that file size is greater then 0). Still does not use AHAH, any help with AHAH is greatly appreciated.

mikeytown2’s picture

Status: Needs review » Needs work

committed. Still looking for AHAH solution.

mikeytown2’s picture

Title: Generation of .htaccess rules on performance page. » AHAH update textarea for .htaccess rules on performance page.
Status: Needs work » Active
mikeytown2’s picture

Title: AHAH update textarea for .htaccess rules on performance page. » AHAH update textarea for .htaccess rules on performance >> boost page.
Priority: Normal » Minor
mikeytown2’s picture

Status: Active » Postponed

Marking this postponed until it's needed or someone submits a patch.

juan_g’s picture

Mike wrote:

In terms of using php to modify the .htaccess file, Wordpress modifies the .htaccess file, so it is doable

Yes, WP Super Cache (plugin for static file caching), the Boost equivalent for WordPress, automatically inserts mod_rewrite rules into the .htaccess file during installation.

mikeytown2’s picture

Status: Postponed » Closed (fixed)

Closing this since it is on its own tab now, thus AHAH is not needed.