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.
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:
and www to non-www
stopping people going to the temporary URLs (replace xxx with server no.)
stopping people going to subdomains
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:
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:
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:
Multiple addresses can be added by using multiple denylines, and ranges of addresses can be specified by using partial addresses, ie:
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’) .
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.