.htaccess Tutorials and Sample .htaccess Files

.htaccess file examples and code to get you up and running. This is the index of my favorite apache HTTP (htaccess, mod_rewrite, httpd.conf) examples, solutions, ideas, htaccess tips, apache tricks and .htaccess sample files. Some of my best server tricks and htaccess configuration techniques aren’t yet here, but are on their way. I like to semi-hide the very best solutions throughout these articles so that only the hungry find it. But 99% of these .htaccess articles are full of easy to use, cut-and-paste-ready htaccess example snippets.

Note: new section on mod_security!

For Webmasters

Custom HTTP Headers

PHP htaccess tips

301 Redirects without mod_rewrite

mod_rewrite tips and tricks

Speed with .htaccess Caching

htaccess Password Protection

Security with Apache htaccess

SSL encryption in htaccess, HTTPS

Apache Variable fun mod_env

Elite .htaccess Security with MOD_SECURITY

SetEnvIf and SetEnvIfNoCase Examples

.htaccess Core Directives

Here are some of the directives included in the core of apache httpd that you may utilize in .htaccess files.

Files
Container for directives affecting files matching specified patterns
Limit
Container for authentication directives when accessed using specified HTTP methods
LimitExcept
Container for authentication directives to be applied when any HTTP method other than those specified is used to access the resource
IfModule
Container for directives based on existance of specified modules
IfDefine
Container for directives based on existance of command line defines
FilesMatch
Container for directives affecting files matching specified patterns
AuthType
An HTTP authorization type (e.g., “Basic”)
AuthName
The authentication realm (e.g. “Members Only”)
Require
Selects which authenticated users or groups may access a protected space
Satisfy
access policy if both allow and require used (’all’ or ‘any’)
AddDefaultCharset
The name of the default charset to add to any Content-Type without one or ‘Off’ to disable
AcceptPathInfo
Set to on or off for PATH_INFO to be accepted by handlers, or default for the per-handler preference when AllowOverride includes FileInfo
ErrorDocument
Change responses for HTTP errors
Options
Set a number of attributes for a given directory
DefaultType
the default MIME type for untypable files
FileETag
Specify components used to construct a file’s ETag
ServerSignature
En-/disable server signature (on|off|email)
ContentDigest
whether or not to send a Content-MD5 header with each request
LimitRequestBody
Limit (in bytes) on maximum size of request message body
LimitXMLRequestBody
Limit (in bytes) on maximum size of an XML-based request body
ForceType
a mime type that overrides other configured type
SetHandler
a handler name that overrides any other configured handler
SetOutputFilter
filter (or ; delimited list of filters) to be run on the request content
SetInputFilter
filter (or ; delimited list of filters) to be run on the request body
AddOutputFilterByType
output filter name followed by one or more content-types

Apache Authorization

.htaccess directives for controlling authorization (AuthDBMGroupFile, AuthDBMUserFile, AuthGroupFile, trunk/mod/mod_authn_core.html#authname, trunk/mod/mod_authn_core.html#authtype, trunk/mod/mod_authn_file.html#authuserfile, trunk/mod/mod_authz_core.html#require).

Apache Files and Information

.htaccess directives controlling document types (defaulttype, errordocument, forcetype, trunk/mod/mod_negotiation.html#languagepriority, sethandler, setinputfilter, setoutputfilter, trunk/mod/mod_headers.html#header, trunk/mod/mod_headers.html#requestheader, trunk/mod/mod_setenvif.html#setenvif, trunk/mod/mod_setenvif.html#setenvifnocase, BrowserMatch, CookieExpires, CookieDomain, CookieStyle, CookieTracking, CookieName, trunk/mod/mod_rewrite.html directives RewriteEngine, RewriteOptions, RewriteBase, trunk/mod/mod_rewrite.html#rewritecond, trunk/mod/mod_rewrite.html#rewriterule) and Action from mod_actions.

Apache Directory Indexing

.htaccess directives controlling directory indexing (AddDescription, AddIcon, AddIconByEncoding, AddIconByType, DefaultIcon, trunk/mod/mod_dir.html#directoryindex, FancyIndexing, HeaderName, IndexIgnore, IndexOptions, ReadmeName).

Apache Access Control

.htaccess directives controlling host access (trunk/mod/mod_authz_host.html#allow, trunk/mod/mod_authz_host.html#deny and Order).

.htaccess Tutorial Index |


Related Articles