function boost_update_htaccess in Boost 6
Helper function to update htaccess Inserts or removes the autogenerated boost rules
@TODO Make this work with subdirectory installs
Parameters
$enable: Whether to patch .htaccess to work with boost.
Return value
TRUE or nonzero on success, FALSE if error
2 calls to boost_update_htaccess()
- boost_admin_htaccess_page_submit in ./
boost.admin.inc - Submit handler for boost_admin_htaccess_page
- boost_uninstall in ./
boost.install - Implementation of hook_uninstall().
File
- ./
boost.admin.inc, line 1498 - All the code for the Boost module's administrative interface.
Code
function boost_update_htaccess($enable = TRUE, $verbose = TRUE) {
$filename = '.htaccess';
$text = file_get_contents($filename);
// Strip out the lines from BOOST START to BOOST END inclusive, if it exists
$text = preg_replace('/^[^#]*### BOOST START ###.*### BOOST END ###[^\\n]*[\\n]*/ims', "\n", $text);
// Inject the rules before '# Rewrite URLs of the form'
if ($enable) {
$rules = boost_admin_generate_htaccess();
$text = preg_replace('/^[^#]*# Rewrite URLs of the form/im', "\n" . $rules . "\$0", $text);
}
boost_htaccess_cache_dir_put();
$result = file_put_contents($filename, $text);
if ($verbose) {
if ($result) {
drupal_set_message($enable ? t('Boost rules written to .htaccess') : t('Boost rules removed from .htaccess'));
}
else {
drupal_set_message(t('Unable to write to .htacess'), 'error');
}
}
}