You are here

htaccess.module in Htaccess 8.2

Same filename and directory in other branches
  1. 7.2 htaccess.module
  2. 7 htaccess.module

Htaccess is a module which autogenerates a Drupal root htaccess file based on your settings.

File

htaccess.module
View source
<?php

/**
 * @file
 * Htaccess is a module which autogenerates a Drupal root htaccess
 * file based on your settings.
 */
define('HTACCESS_TEMPLATE_PATH', drupal_get_path('module', 'htaccess') . '/includes/htaccess.txt');

/**
 * Implementation of hook_help()
 */
function htaccess_help($path, $arg) {
  $output = '';
  switch ($path) {
    case "admin/help#htaccess":
      $output = '<p>' . t("Auto generate htaccess. ") . '</p>';
      break;
  }
  return $output;
}
function htaccess_cron() {

  // try to get current htaccess content
  $root_path = \Drupal::root();
  $htaccess_filepath = $root_path . '/.htaccess';
  $htaccess_current = file_get_contents($htaccess_filepath);
  if ($htaccess_current) {

    // Get the current htaccess deployed
    $htaccess_deployed = db_select('htaccess', 'h')
      ->fields('h')
      ->condition('deployed', 1, '=')
      ->execute()
      ->fetchAssoc();
    if ($htaccess_deployed) {
      $htaccess_deployed = $htaccess_deployed['htaccess'];

      // Compare the two results
      if ($htaccess_current === $htaccess_deployed) {
        \Drupal::config('htaccess.settings')
          ->clear('htaccess_altered')
          ->save();
      }
      else {
        drupal_set_message(t('The htaccess seems to be altered.'), 'warning');
        \Drupal::configFactory()
          ->getEditable('htaccess.settings')
          ->set('htaccess_altered', true)
          ->save();
      }
    }
  }
}

Functions

Namesort descending Description
htaccess_cron
htaccess_help Implementation of hook_help()

Constants

Namesort descending Description
HTACCESS_TEMPLATE_PATH @file Htaccess is a module which autogenerates a Drupal root htaccess file based on your settings.