Frequently Used .htaccess Directives
Article translated by machine
This text is a machine translation. A revised version is planned.
Please use the “Print” function at the bottom of the page to create a PDF.
For Linux Web Hosting and Managed Dedicated Servers
Learn about some frequently used .htaccess directives and their purpose.
Activate Directory Listing
You can use directory listing to display the folder and file structure of your web space in the browser. This can then be viewed from the outside by every visitor. For security, we have disabled the function on our servers by default. You can enable it by adding the code below to your .htaccess file.
# Activates the Directory Listing (deactivated for security reasons)
#
Options +Indexes
Disable File Matching
Switching off the CheckSpelling function will stop the server from displaying a list of files that seem to match the mispelled page, or automatically loading the closest matching page name.
# Prevents the server from detecting spelling errors or incorrect
# capitalization in file names. Shows a page not found error instead
# of loading the file or page that most closely resembles the spelling.
#
CheckSpelling off
Allow Other File Extensions for CGI Applications
If you want to run CGI applications with the file extensions .cgi or.asp, define this with the following command.
# Allows other file extensions to be run as CGIs
#
AddHandler cgi-script .cgi .asp
Specifying the MIME Type for Specific File Types
If you want to alter which application is used to open a specify file type, define the MIME type accordingly.
# Force the Microsoft Excel MIME type for all .csv files.
# The file then opens in Excel rather than a text editor.
#
AddType application/vnd.ms-excel .csv
Activate Rewrite Engine
You need this basic function when creating rewrite rules
# Activate the rewrite engine
#
RewriteEngine on
Set up Rewrite Rules
If you want to redirect the call of an Internet address (URL) in a different, predefined way, you can specify this using RewriteRules.
# Example Rewrite-Rule:
# Rewrites http://example.com/xyz.html to http://example.com/index.php?xyz
#
RewriteEngine on
RewriteBase /
RewriteRule ^([a-z]+)\.html$ /index.php?$1 [R,L]
Use Custom Error Pages
You can define which page should be shown for various errors, such as the 404 PAGE NOT FOUND error.
# Rewrite-Rule for showing the errordocument.html page whenever
# a file or folder is not found, as well as when the following
# HTML errors occur: 400, 401, 403, 404, and 500
#
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /errordocument.html
ErrorDocument 400 /errordocument.html
ErrorDocument 401 /errordocument.html
ErrorDocument 403 /errordocument.html
ErrorDocument 404 /errordocument.html
ErrorDocument 500 /errordocument.html
Due to security settings or similar, we reserve the right at any time to completely or partially overwrite these directives or to prevent their use.