How To Create & Edit The .htaccess File
.htaccess is the default name of a configuration file that contains server directives that tell the server how to behave. One common use for an htaccess file is to restrict access to specific files or directories on the Internet, or to specify a particular webpage to be accessed when the file requested by the browser is not found (error 404). The .htaccess file usually resides in the root public_html directory of your server.
.htaccess Examples
# Disable directory browsing
Options All -Indexes
# Redirect a single page
Redirect 301 /oldpage.html http://www.example.com/newpage.html
# Redirect from old domain to new domain
RewriteEngine On
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L]
# Custom Error Pages
ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
# Prevent access throughout the afternoon
RewriteEngine On
RewriteCond %{TIME_HOUR} ^12|13|14|15$
RewriteRule ^.*$ - [F,L]
# Disable hot linking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
# Just allow my IP to access
order deny,allow
deny from all
allow from xxx.xx.x.xxx
# Deny visitors by IP address
order allow,deny
deny from 111.111.111.111
deny from 123.123.123.
allow from all
# Deny all IPs except mine and redirect
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^12\.12\.12\.12
RewriteRule .* http://www.redirecturl.com [R=302,L]