public function HtaccessWriter::write in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/File/HtaccessWriter.php \Drupal\Core\File\HtaccessWriter::write()
- 9 core/lib/Drupal/Core/File/HtaccessWriter.php \Drupal\Core\File\HtaccessWriter::write()
Creates a .htaccess file in the given directory.
@internal
Parameters
string $directory: The directory.
bool $deny_public_access: (Optional) FALSE indicates that $directory should be a web-accessible directory. Defaults to TRUE which indicates a private directory.
bool $force_overwrite: (Optional) Set to TRUE to attempt to overwrite the existing .htaccess file if one is already present. Defaults to FALSE.
Return value
bool TRUE if the .htaccess file was saved or already exists, FALSE otherwise.
See also
\Drupal\Component\FileSecurity\FileSecurity::writeHtaccess()
File
- core/
lib/ Drupal/ Core/ File/ HtaccessWriter.php, line 85
Class
- HtaccessWriter
- Provides functions to manage Apache .htaccess files.
Namespace
Drupal\Core\FileCode
public function write($directory, $deny_public_access = TRUE, $force_overwrite = FALSE) {
if (StreamWrapperManager::getScheme($directory)) {
$directory = $this->streamWrapperManager
->normalizeUri($directory);
}
else {
$directory = rtrim($directory, '/\\');
}
if (FileSecurity::writeHtaccess($directory, $deny_public_access, $force_overwrite)) {
return TRUE;
}
$this->logger
->error("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <pre><code>@htaccess</code></pre>", [
'%directory' => $directory,
'@htaccess' => FileSecurity::htaccessLines($deny_public_access),
]);
return FALSE;
}