function htaccess_install in Htaccess 8.2
Same name and namespace in other branches
- 7.2 htaccess.install \htaccess_install()
Implements hook_install(). Store the Drupal default htaccess into database.
File
- ./
htaccess.install, line 66 - Htaccess module install file.
Code
function htaccess_install() {
$htaccess_template = file_get_contents(HTACCESS_TEMPLATE_PATH);
$with_www_default = "#RewriteCond %{HTTP_HOST} .\n";
$with_www_default .= "#RewriteCond %{HTTP_HOST} !^www\\. [NC]\n";
$with_www_default .= "#RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]\n";
$without_www_default = "#RewriteCond %{HTTP_HOST} ^www\\.(.+)\$ [NC]\n";
$without_www_default .= "#RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]\n";
$search = array(
"%%%rules_before%%%",
"%%%symbolic_links%%%",
"%%%ssl_force_redirect%%%",
"%%%with_www%%%",
"%%%without_www%%%",
"%%%boost_rules%%%",
);
$replace = array(
"",
"+FollowSymLinks",
"",
$with_www_default,
$without_www_default,
"",
);
$htaccess_origin = str_replace($search, $replace, $htaccess_template);
db_insert('htaccess')
->fields(array(
'name' => 'default',
'description' => t('The default htaccess shipped with Drupal.'),
'htaccess' => $htaccess_origin,
'created' => REQUEST_TIME,
))
->execute();
}