What Directives can be Used in an .htaccess File?

An `.htaccess` file, when placed in a directory, allows you to override some server configuration settings for that specific directory and its subdirectories. Here are some common directives that can be used in an `.htaccess` file:

1. RewriteEngine: Enables or disables the Apache `mod_rewrite` module, which allows URL rewriting and redirection. Example:

RewriteEngine On

2. RewriteRule: Defines rules for URL rewriting and redirection. Example:

RewriteRule ^old-page\.html$ new-page.html [R=301,L]

3. Redirect: Redirects clients from one URL to another. Example:

Redirect 301 /old-page.html /new-page.html

4. Options: Sets various options for the directory. Example:

Options -Indexes

5. AllowOverride: Specifies which directives in `.htaccess` files can override server configuration. Example:

AllowOverride All

6. Order: Specifies the order in which the directives should be applied. Example:

Order allow,deny

7. Deny/Allow: Specifies which clients are allowed or denied access to the resources. Example:

Deny from 192.168.1.1

8. AuthType, AuthName, AuthUserFile, Require: Configures authentication settings for password-protected directories. Example:

AuthType Basic
AuthName "Restricted Area"
AuthUserFile /path/to/.htpasswd
Require valid-user

9. ErrorDocument: Specifies custom error pages for different HTTP error codes. Example:

ErrorDocument 404 /errors/not-found.html

10. AddType, AddHandler: Associates file extensions with specific MIME types or handlers. Example:

AddType application/x-httpd-php .php
AddHandler application/x-httpd-php .php

These are just some of the common directives. There are many more directives available for various purposes, including caching, compression, security, and more. It’s important to note that not all directives may be supported depending on the server’s configuration and the modules enabled.