jump to navigation

Apache configuration notes March 25, 2011

Posted by Tournas Dimitrios in Uncategorized.

This article will list some configurations on the Apache server for every day use . You can use .htaccess files to control a wide variety of webserver behavior. The .htaccess file will affect all subdirectories below the one in which the .htaccess file resides.

  • Stop people from getting directory listings when I dont have an index page:
    If a URL which maps to a directory is requested, and the there is no DirectoryIndex (e.g., index.html) in that directory, then the server by default will return a formatted listing of the contents of that directory.To turn these directory listings off, simply add to (or create) an .htaccess file in the directory you want to protect and insert:
    Options  -Indexes
  • Show a default page other than index.html:
    The DirectoryIndex directive controls what page will be shown when a client asks for a directory in their browser.By default, DirectoryIndex directive is usually set to:
    DirectoryIndex  index.html index.htm default.htm index.php
    Apache will look for each of the above files, in order, and serve the first one it finds when a visitor requests just a directory. If the webserver finds no files in the current directory that match names in the DirectoryIndex directive, then a directory listing will be displayed to the browser, showing all files in the current directory( If you don’t want that to happen see previous how-to) .
    If you want to change your own DirectoryIndex to either add a different filename, shorten the list, or change the order of the list, just create a file named .htaccess in the directory where you want this behavior to occur. Inside the .htaccess file, put a single line beginning with DirectoryIndex followed by the list of filenames that you want Apache to serve first when a directory has been requested, like so:
    DirectoryIndex  index.phtml  start.html
    The above directive must be all on a single line in the .htaccess file. If you capitalize or change the case of any of your filenames, then they won’t match if they are not capitalized the same way in the DirectoryIndex directive. “INDEX.HTML” is not the same as “index.html” .If you have capitalized any of the filenames of your webpages, then you either need to rename them all lowercase, or you should create your own custom DirectoryIndex directive as described above, using whatever filename capitalization you want.
    Please read the Apache documentation on DirectoryIndex
  • Block certain IP addresses from seeing your website :
    You can block certain IP addresses from accessing your site by using a Deny directive in an .htaccess file. For example, if you put the following .htaccess file in a directory, then it would operate on all directories beneath it:
    Deny from
    Deny From 192.168.55
    The 1st Deny directive would block the exact IP address The 2nd Deny directive would block all IP addresses fitting the pattern 192.168.55, including,,, etc.
  • Stop other websites from using your bandwidth while they steal images, flash, etc. from my site :
    It is possible for other websites to serve your content to their visitors by linking to your objects from their webpages. For example, http://www.badsite.com might have some html on their site like  <img src=”http://yoursite.com/img.gif” alt=”” /> .This type of bandwidth theft can happen with any media type (zip, pdf, swf, wav, mov, mp3, etc.), not just images. Use the following mod_rewrite rules in .htaccess file :
    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://yoursite.com [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.yoursite.com [NC]
    RewriteRule .*.(gif|jpg|swf|png)$ – [NC,F]
  • Make apache recognize different MIME types :
    You use one or more AddType directives in an .htaccess file located in or above the directory where you want the new types to be recognized.
    AddType text/html .html
    AddType image/gif .gif
    The AddType directive is fully documented at http://httpd.apache.org/docs/mod/mod_mime.html#addtype
  • Protecting a directory with mod_auth_mysql
  • Deny web access to a particular file :
    If you have a file underneath your DocumentRoot (accessible to a browser) that you do not want anyone to be able to view in a browser, you can block access to it with a “Files ” directive
    <Files ~ “^somefile\.ext”>
    Order allow,deny
    Deny from all


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s