function file_htaccess_lines

Same name in other branches
  1. 8.9.x core/includes/file.inc \file_htaccess_lines()

Returns the standard .htaccess lines that Drupal writes to file directories.

Parameters

$private: (Optional) Set to FALSE to return the .htaccess lines for an open and public directory. The default is TRUE, which returns the .htaccess lines for a private and protected directory.

Return value

A string representing the desired contents of the .htaccess file.

See also

file_create_htaccess()

Related topics

2 calls to file_htaccess_lines()
FileDirectoryTest::testFileCheckDirectoryHandling in modules/simpletest/tests/file.test
Test directory handling functions.
file_create_htaccess in includes/file.inc
Creates a .htaccess file in the given directory.

File

includes/file.inc, line 525

Code

function file_htaccess_lines($private = TRUE) {
    $lines = <<<EOF
# Turn off all options we don't need.
Options None
Options +FollowSymLinks

# Set the catch-all handler to prevent scripts from being executed.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
<Files *>
  # Override the handler again if we're run later in the evaluation list.
  SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003
</Files>

# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php5.c>
  php_flag engine off
</IfModule>
<IfModule mod_php7.c>
  php_flag engine off
</IfModule>
# From PHP 8 there is no number in the module name.
<IfModule mod_php.c>
  php_flag engine off
</IfModule>
EOF;
    if ($private) {
        $lines = <<<EOF
# Deny all requests from Apache 2.4+.
<IfModule mod_authz_core.c>
  Require all denied
</IfModule>

# Deny all requests from Apache 2.0-2.2.
<IfModule !mod_authz_core.c>
  Deny from all
</IfModule>
EOF
 . "\n\n" . $lines;
    }
    return $lines;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.