A .htaccess file is a optional directory-level configuration file, that allows for decentralized management of web server configuration. A lot of PHP scripts will come with their own .htaccess but if you know what you are doing you can create and maintain your own.

For security reasons we disable ALL ‘option’ commands by default. We are happy to enable these if customers need them – simply contact support and request this.

Below are just some common uses and tweaks asked for by customers:

Redirecting domain to www.domain

Some search engines complain if say http://mysite.com/ and http://www.mysite.com/ have the same content (which they will as our servers make the www. part optional). One way around this is to permanently redirect the non-www address to the www address. This can simply be done with the following rules in a .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

and www to non-www

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]

stopping people going to the temporary URLs (replace xxx with server no.)

RewriteEngine On
RewriteCond %{HTTP_HOST} server
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

stopping people going to subdomains

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

Setting up a Custom 404 error page

1. First create a ‘404 Error Page’ of your own design and call it error.html (for example).

2. Next create (or edit) a file called .htaccess in your domain root folder and add the following:

ErrorDocument 404 http://www.yourdomain/error.html

It is best to place these two files in the root directory of your site. Any attempted access to a file that doesn’t exist anywhere in your site will bring up your custom error document.

Changing the default index page

By default the server looks for certain files in the following order to display as the default index page: index.htm, index.shtml, Default.htm default.htm, index.php, INDEX.htm, Index.htm, INDEX.html, Index.html, index.phtml, index.php, index.wml, Index.wml, home.htm, home.html, Home.htm, Home.html

1. To change this order you need to use the DirectoryIndex command in a .htaccess file:

DirectoryIndex filename.htm anotherfile.html

Blocking certain IP addresses

Sometimes it may be necessary to block certain IP addresses from accessing your website. To do this the following .htaccess rules can be used:

<Limit GET POST>
order allow,deny
allow from all
deny from

Multiple addresses can be added by using multiple denylines, and ranges of addresses can be specified by using partial addresses, ie:

deny from 65.10.

Would block everything from IP addresses starting 65.10.

Disabling folder browsing

There are a few ways of stopping people browsing your site folders. One is just to put a empty index.html file in the folder you want to protect. To turn off all site folder browsing then you can do this by adding the following line to a .htaccess file in your domain root folder (‘option’ commands are not enabled on your domain by default so please contact support to request we ‘enable options’) .

options -indexes

Running PHP 5 FastCGI in a subfolder

Adding the following to a .htaccess in a folder will make .php files run using PHP5 FastCGI mode in that folder without affecting other parts of the site that might need PHP 5 Module mode.

AddHandler php5-fcgi .php
Action php5-fcgi /cgi-bin/php5.fcgi