Here are some common .htaccess tricks to help save you some time!
(Warning: .htaccess is a very powerful configuration file. Even the slightest syntax error can result in severe malfunction to your server. You should make a back-up of everything, included any existing .htaccess files before you begin editing. It is also a good idea to check your website throughout your editing process to ensure everything is still functioning properly. If you notice an error, apply your backup immediately).
For more tips, check out “.htaccess tips part 2″ !
Enable Basic Rewriting
Not all servers have mod_rewrite (basic rewriting) enabled. You can do this by adding the following to the .htaccess file in the root directory:
# this will enable basic rewriting
RewriteEngine on
.htaccess Comments
To make a commented line, simply apply “#” before the line. This instructs the server to ignore the line.
Example:
# this line is commented out
# you must add a “#” for each line
Prevent access to a specific file
To prevent access to a particular file, use the following:
<files filenamehere.jpg># you can use any file extension
order allow,deny
deny from all
</files>
Prevent access to multiple file types
To prevent access to multiple file types, use the following:
<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order Allow,Deny
Deny from all
</FilesMatch>
Prevent Directory Browsing
Using this will prevent the listing of all files in a particular directory. You can create an individual .htaccess file for each specific folder you wish to control:
# disable directory browsing
Options All -Indexes
Or, to enable directory browsing, use this:
# enable directory browsing
Options All +Indexes
Change the Default Index Page
If you have a page that you want your visitors to see instead of your current “index.html” or whatever it is, use this to re-define the new default page. This must exist in the ROOT directory for which you wish to replace the file.
DirectoryIndex newfilename.html
# you can use any extension
For more tips, check out “.htaccess tips part 2″ !
[...] or check out “.htaccess tips part 1″. [...]