.htaccess is a configuration file Apache web server looks for in the currently accessed directory. This file may contain all sorts of directives that tell the web server how to behave.
Here is a simple .htaccess file you can put in your /htdocs folder. You can use it as a template upon which to build or use a completely custom one. Below are some other .htaccess directives you may find useful.
Always chmod your .htaccess with 644 permissions.
.htaccess: ## basic .htaccess# Line starting with # is a comment.
# To display script errors
php_value display_errors on
# To set default charset to international
php_value default_charset utf-8
AddDefaultCharset utf-8
# To further manage URL rewrite conditions
RewriteEngine On
RewriteBase /
# To have all www.mydoma.in traffic
# redirect to mydoma.in
RewriteCond %{HTTP_HOST} !(^mydoma) [NC]
RewriteRule ^(.*)$ http://mydoma.in/$1 [R=301,L]
# To have all sitestore.com traffic
# redirect to www.sitestore.com
RewriteCond %{HTTP_HOST} !(^www) [NC]
RewriteRule ^(.*)$ http://www.sitestore.com/$1 [R=301,L]
# To throw 403 Forbidden error and redirect
# when accessing .htaccess file
RewriteRule ^(\.htaccess)$ / [R=403,L]
# To disable directory traversing
# (e.g. spilling its contents)
Options All -Indexes
# To optionally process .html (or any)
# filetype as php script
AddType application/x-httpd-php .html
# To force download of files
# with extension .ogg
AddType application/octet-stream .ogg
# To redirect all file1.php traffic
# to file2.php
Redirect 301 /old/file1.php /new/file2.php
# To set custom error pages
ErrorDocument 403 /e403forbidden.html
ErrorDocument 404 /e404notfound.html
# To only allow traffic from IP/range
Order deny,allow
Deny from all
Allow from 81.32.64.88
Allow from 81.32.64.88/24
You may further help yourself with this mod_rewrite cheat sheet and this detailed list of apache directives and google .htaccess discussion group.
You may find some directives not working. Not all modules are installed, so directives that apply to mod_ssl, for instance, will not work, show an error or redirect. Please refer to the output of <?php phpInfo() ?> PHP script for additional information.
Note, all clear-text traffic is already gzip compressed. Some scrapers, spiders, spamming bots, etc. are already blocked; all browsers, search engines, indexes, etc. are fully supported. Caching is prevented so content is always served fresh.
Q: My website is inaccessible or returns 500 internal server error or redirects to an outside webpage?
A: See answer #1 and answer #2 in our FAQ.


