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).
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
To make a commented line, simply apply “#” before the line. This instructs the server to ignore the line.
# 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
deny from all
Prevent access to multiple file types
To prevent access to multiple file types, use the following:
Deny from all
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.
# you can use any extension