.htaccess tips & tricks

If your .htaccess does not work. Open your apache configuration and find the block

Add the following line to activate htaccess

Its good to turn on rewrite engine in apache

secure your .htaccess file

Don’t list files in index pages

You can specify the rewrite base directory of your application

Redirect non www domain to www domain

Expiry based on file types

Compress files based on extensions

Compress based on extension headers

Expiry dates based on file extensions

Disable directory browsing

Enable directory browsing

Create custom error pages.

Custom error documents are configured using the ErrorDocument directive, which may be used in global, virtualhost, or directory context. It may be used in .htaccess files if AllowOverride is set to FileInfo.

Redirect from a specific file to a new file

WildCard Redirect / Redirecting from one folder to a new folder

Password protection to a directory

Install apache utilities to generate password

You can find an online tool to make htaccess password and skip the above steps

http://www.htaccesstools.com/htpasswd-generator/

Password Protect single file

Password Protect multiple files

Remove Comments from pagespeed

Stop hotlinking

Disable the server signature

Set server timezone

Set the default character set

Disguise Script Extensions. Serve foo files as php files

Secure Directories by IP Address and/or Domain
In the following example, all IP addresses are allowed access except for 12.345.67.890 and domain.com:

In the following example, all IP addresses are denied access except for 12.345.67.890 and domain.com:

Deny access to evil robots site rippers offline browsers and other nasty scum

CHMOD Various File Types

Automatically correct simple spelling errors

Download multimedia files rather than display them to browser

Redirect an entire site via 301

Redirect an entire site via permanent redirect

You can get more information at http://perishablepress.com/stupid-htaccess-tricks/