function file_create_htaccess


Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/
cis7 file_create_htaccess($directory, $private = TRUE, $force_overwrite = FALSE)
cle7 file_create_htaccess($directory, $private = TRUE, $force_overwrite = FALSE)
elmsmedia7 file_create_htaccess($directory, $private = TRUE, $force_overwrite = FALSE)
icor7 file_create_htaccess($directory, $private = TRUE, $force_overwrite = FALSE)
meedjum_blog7 file_create_htaccess($directory, $private = TRUE, $force_overwrite = FALSE)
mooc7 file_create_htaccess($directory, $private = TRUE, $force_overwrite = FALSE)

Creates a .htaccess file in the given directory.


$directory: The directory.

$private: FALSE indicates that $directory should be an open and public directory. The default is TRUE which indicates a private and protected directory.

$force_overwrite: Set to TRUE to attempt to overwrite the existing .htaccess file if one is already present. Defaults to FALSE.

Related topics

3 calls to file_create_htaccess()
backup_migrate_destination_files::check_web_dir in sites/all/modules/ulmus/backup_migrate/includes/
Check that a web accessible directory has been properly secured, othewise attempt to secure it.
file_ensure_htaccess in includes/
Creates a .htaccess file in each Drupal files directory if it is missing.
system_check_directory in modules/system/system.module
Checks the existence of the directory specified in $form_element.


includes/, line 477
API for handling file uploads and server file management.


function file_create_htaccess($directory, $private = TRUE, $force_overwrite = FALSE) {
  if (file_uri_scheme($directory)) {
    $directory = file_stream_wrapper_uri_normalize($directory);
  else {
    $directory = rtrim($directory, '/\\');
  $htaccess_path = $directory . '/.htaccess';

  if (file_exists($htaccess_path) && !$force_overwrite) {
    // Short circuit if the .htaccess file already exists.

  $htaccess_lines = file_htaccess_lines($private);

  // Write the .htaccess file.
  if (file_put_contents($htaccess_path, $htaccess_lines)) {
    drupal_chmod($htaccess_path, 0444);
  else {
    $variables = array(
      '%directory' => $directory,
      '!htaccess' => '<br />' . nl2br(check_plain($htaccess_lines)),
    watchdog('security', "Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables, WATCHDOG_ERROR);



Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/ in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/
The website encountered an unexpected error. Please try again later.