Apache: Useful .htaccess tips & tricks

.htaccess is just not file extension rather an effective tool to manage Web Server configurations that makes life very easy specially for web hosting companies. From Authorization/Authentication to URL rewriting, Server side includes (SSI) to Directory Listing, Customized error handling to Cache control & managing MIME type, everything can be controlled from this file and that even without restarting web server. On top of it, .htaccess files affect the directory they are placed in and all sub-directories.

Hiding webpage extensions & redirecting

Redirecting non-www to www version

Redirecting www to non-www in subfolder

Redirect the site IP address (A.B.C.D) to the domain name

Turn http www mode into https non-www mode

Serve content from a different server or host or sub-domain as a subfolder without redirection

Control caching

Defining MIME types for different file type

Enable GZIP compression

Redirection for Maintenance windows

Force lowercase urls

Block external access to sensitive files

Prevent Directory Listing

Set external redirection map file

Allow cross-domain Web fonts to work

Allow resources like fonts, js and css to be loaded from sub-domain strictly

Try playing around htaccess rules using http://htaccess.madewithlove.be/