htaccess.install in Htaccess 8.2
Same filename and directory in other branches
Htaccess module install file.
File
htaccess.installView source
<?php
/**
* @file
* Htaccess module install file.
*/
/*
* Implements hook_schema().
* Create a table which will store htaccess profile.
*/
function htaccess_schema() {
$schema['htaccess'] = array(
'description' => 'The table for htaccess.',
'fields' => array(
'id' => array(
'description' => t('The unique identifier for a htaccess.'),
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'name' => array(
'description' => t('The profile name of the htaccess.'),
'type' => 'text',
'not null' => TRUE,
),
'description' => array(
'description' => t('The description of the htaccess.'),
'type' => 'text',
),
'htaccess' => array(
'description' => t('The htaccess rules generated.'),
'type' => 'text',
'not null' => TRUE,
),
'deployed' => array(
'description' => t('Indicates the current htaccess used.'),
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'description' => t('The created date of the generated htaccess rules.'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'htaccess_created' => array(
'created',
),
),
'unique keys' => array(
'id' => array(
'id',
),
),
'primary key' => array(
'id',
),
);
return $schema;
}
/**
* Implements hook_install().
* Store the Drupal default htaccess into database.
*/
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();
}
/**
* Implements hook_requirements().
*/
function htaccess_requirements($phase) {
$requirements = array();
$t = 't';
if ($phase == 'runtime') {
// Check if the htaccess has been altered
if (\Drupal::config('htaccess.settings')
->get('htaccess_altered') == true) {
$requirements['htaccess'] = array(
'title' => $t('Htaccess module'),
'description' => $t('Htaccess seems to be altered.'),
'severity' => REQUIREMENT_WARNING,
'value' => $t('Htaccess altered'),
);
}
}
return $requirements;
}
Functions
Name![]() |
Description |
---|---|
htaccess_install | Implements hook_install(). Store the Drupal default htaccess into database. |
htaccess_requirements | Implements hook_requirements(). |
htaccess_schema |