martes, 10 de julio de 2012

Parámetros en .htaccess


.htaccess (Acceso de Hiper-Texto) es un archivo de texto que Apache usa para crear reglas sobre los directorios y los archivos. Tiene múltiples funciones y en lo personal me parece una herramienta sumamente interesante.
A manera de glosario anexo simbologías utilizadas en el archivo .htaccess con la intención de que podamos comprender mejor el código y a la vez personalizarlo según necesidades específicas.

Se ignora la línea.
[F] 
Forbidden: para forzar un acceso denegado. 403 Forbidden.
[L]
Last rule: para indicar que es la última regla que debe aplicarse
[N]
Next: indica continuación hasta que las directivas sean logradas
[G]
Gone: indica al servidor entregar "Gone" (ya no existe)
[P]
Proxy: instruye al servidor para manejar los pedidos por mod_proxy
[C]
Chain: Instruye al servidor para encadenar la regla actual con la regla previa.
[R]
Redirect: indica redirección.
[NC]
No Case: para indicar que en la directiva no debe distinguirse entre mayúsculas y minúsculas.
[PT]
Pass Through: pasa el URL al Apache para seguir procesando.
[OR]
Or: para indicar que la expresión actual debe interpretase como una alternativa a la anterior.
[NE]
No Escape: instruye al servidor para analizar las salidas sin escapar carácteres.
[NS]
No Subrequest: para saltar directivas de sub-pedidos internos.
[QSA]
Append Query String: para agregar un query string al final de la expresión (URL).
[S=x]
Skip: para saltar las siguientes "x" reglas.
[E=variable:value]
Environmental Variable: para agregar una variable a un valor.
[T=MIME-type]
Mime Type: declara mime-type al recurso.
[]
dentro de los paréntesis se encierran carácteres que definen los resultados.
[]+
se utiliza para hacer combinaciones.
[^]
excluye los carácteres dentro del paréntesis, de los resultados. Ejemplo [^xyz].
[a-z]
solamente letras.
[a-z]{1,10}
palabras entre 1 y 10 caracteres.
[0-9]
solamente números.
[0-9]{4}
números de 4 cifras.
(.*)
cualquier expresión.
a{n}
especifica el número exacto del caracter que le precede.
a{n,}
especifica el número "o más" del caracter que le precede.
a{n,m}
especifica un rango entre "n" y "m". Ejemplo x{4,7} resulta 4,5,6 o 7 x´s.
()
agrupa carácteres
^
denota "el principio" del argumento.
$
denota "el fin" del argumento.
?
Declara como opcional el caracter anterior.
!
declara negación (excepto). Ejemplo: "!string" resulta "excepto string".
.
el punto indica "cualquier caracter arbitrario".
-
intrucción “not to”.
+
declara "uno o más" del caracter que le precede.
|
declara "or". Ejemplo (x|y) resulta "x" o "y".
\
para leer caracteres especiales. Ejemplo “\.” indica literalmente un punto.
/*
indica cero o más "/".
.*
indica cero o más caracteres arbitrarios.
^$
indica un "empty string".
^.*$
pauta estándar para obtener todo.
[^/.]
define, un caracter que no es "/" ni ".".
[^/.]+
define, ningún número de caracter que tenga "/" o ".".
http://
es literalmente “http://”.
^domain.*
define un string que comienza con el término "domain" y continúa con cualquier número de caracteres.
^domain\.com$
define exactamente “domain.com”.
-d
prueba si el string es un directorio existente.
-f
prueba si el string es un archivo existente.
-s
prueba si el archivo en el string no tiene valor cero.

Directivas de .htaccess


Directivas de .htaccessEnviar a un amigo
De forma general se puede decir que las directivas en el .htaccess se componen de tres partes: el tipo de directiva (Options, RewriteCond), los parámetros de la directiva y por último el final de cada línea en que se pueden agregar modificaciones adicionales.
Las expresiones regulares son patrones de cadenas de textos que se definen utilizando símbolos como el de oclusión (^) para indicar el inicio, el del dólar ($) para señalar el final, el cierre de interrogación (?) para un carácter opcional, el asterisco (*) para varios caracteres opcionales.
Los valores que aparecen entre corchetes al final de cada línea son modificadores o acciones. Por ejemplo, para RewriteCond se puede utilizar [NC] para indicar que en la directiva no debe distinguirse entre mayúsculas y minúsculas (no case), u [OR] para indicar que la expresión actual debe interpretase como una alternativa a la anterior: Por su parte, RewriteRule admite otros modificadores propios, como [F] para forzar un acceso denegado (forbidden), o [L] para indicar que es la última regla que debe aplicarse (last rule). Ejemplo:
Cambiando la página por defecto:
Se puede utilizar esta instrucción para cambiar la página por defecto (el orden es importante)
DirectoryIndex inicio.html index.htm index.html index.php

Redireccionar el tráfico web:
Redirect /antiguo.php http://sitio.com/nuevo.php

Limitar los tipos de ficheros que pueden subirse a un directorio
php_value engine off
AddType text/plain .htm .html .shtml

Contenido dependiente del Navegador
Para redirigir el contenido en función del navegador se puede utilizar el valor de "User-Agent" que aparece en la cabecera HTTP de las peticiones, y con el que normalmente se identifica el navegador. Por ejemplo, las siguientes líneas colocadas en un fichero .htaccess harían que cuando un agente solicitará la página index.html se le sirviese la página index.opera.html si se identifica como "Opera/*", la página index.mozilla.html si se identifica como "Mozilla/*" y la página index.html en cualquier otro caso.:
RewriteCond %{HTTP_USER_AGENT} ^Opera/*
RewriteRule ^index\.html$ index.opera.html [L]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/*
RewriteRule ^index\.html$ index.mozilla.html [L]
RewriteRule ^index\.html$ index.html [L]

Los asteriscos en las expresiones regulares de las directivas casan con cualquier cadena de texto. Y en este caso en concreto se utilizan para redirigir el contenido dependiendo del nombre del agente sin tener en cuenta la versión, que suele indicarse a continuación de la barra, como "Mozilla/3.0", "Mozilla/4.0", "Mozilla/5.0", …

Especificar el e-mail por defecto del administrador del server:
# e-mail del administrador del server
SetEnv SERVER_ADMIN nombre@sitio.com

Especificar el lenguaje por defecto del server:
# lenguaje por defecto del server
DefaultLanguage en-US

Declarar específicos MIME types:
# agregar mime types
AddType application/x-shockwave-flash .swf
AddType video/x-flv .flv
AddType image/x-icon .ico

Prevenir accesos al archivo .htaccess:
# asegurar htaccess
<Files .htaccess>
order allow,deny
deny from all
</Files>

Prevenir acceso a un archivo específico:
<files nombre.jpg>
order allow,deny
deny from all
</files>

Prevenir acceso a múltiples archivos (puedes variar las extensiones):
<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order Allow,Deny
Deny from all
</FilesMatch>


Evitar acceso por el navegador a una carpeta sin "index":

Options All -Indexes

Permitir acceso por el navegador:
Options All +Indexes

Evitar el listado de directorios:
IndexIgnore *

Evitar que se muestren tipos de archivo:
IndexIgnore *.wmv *.mp4 *.avi *.etc

Disfrazar la extensión de los archivos:
# los archivos foo se reconocerán como php
AddType application/x-httpd-php .foo

Proteger directorio de un IP y/o dominio:
<Limit GET POST PUT>
order allow,deny
allow from all
deny from 12.345.67.890
deny from .*domain\.com.*
</Limit>

Denegar todo acceso a un directorio excepto el IP especificado:
<Limit GET POST PUT>
order deny,allow
deny from all
allow from 12.345.67.890
allow from .*domain\.com.*
</Limit>

Bloquear visitantes que provienen del dominio especificado:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} scumbag\.com [NC,OR]
RewriteCond %{HTTP_REFERER} wormhole\.com [NC,OR]
RewriteRule .* - [F]
</ifModule>

Denegar acceso de rango de IP (CIDR):
Deny from 10.1.0.0/16
Deny from 80.0.0/8

Permitir acceso de rango de IP (CIDR):
Allow from 10.1.0.0/16
Allow from 80.0.0/8

Denegar rango de IP:
Recuerda que se lee de izquierda, "Cualquier IP que comience con":
Deny from 99.88.77.66
Deny from 99.88.77
Deny from 99.88
Deny from 99

Permitir rango de IP
Allow from 99.88.77.66
Allow from 99.88.77
Allow from 99.88
Allow from 99

Evitar Hotlink:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.com/.*$ [NC]
RewriteRule .*\.(gif|jpg)$ http://www.domain.com/eatme.jpe [R,NC,L]
</ifModule>
Puedes agregar otros sitios debajo de la lìnea en que aparece el dominio:
RewriteCond %{HTTP_REFERER} !^http://(www\.)?sitio\.com/.*$ [NC]

Bloquear robots maliciosos:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule .* - [F]

Se puede personalizar el error generado a estos robots modificando la última línea (RewriteRule) de esta forma:
RewriteRule ^.*$ http://www.pagina_de_error.com [R,L]
Te recomiendo que uses la siguiente línea en tu .htaccess. Referente al bloqueo de Robots y Referers maliciosos:
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?gameday.de.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?play-texas-holdem.gameday.de.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?forever.kz.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?craps.forever.kz.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?roulette-online.forever.kz.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?play-poker.forever.kz.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?onlinecasino.forever.kz.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?texashold-em.freeservers.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?playonline.inn7winter.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?poker-new.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?available-poker.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?free-poker.available-poker.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?texasholdem.prv.pl.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?prv.pl.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?homestead.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?texaspoker.homestead.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?t-e-x-a-s-poker.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?texas-poker.olo.cc.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?holdem-poker.servertown.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?online-poker.played.by.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?empire-poker.black-poker.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?black-poker.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?free.fr.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?pc800cdf.free.fr.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?free-poker.standard-poker.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?cameralover.net.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?golfshoot.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?bitlocker.net.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?bayfronthomes.net.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?cafexml.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?turniptruck.com.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?trojan-horse.co.uk.*$ [NC]
RewriteRule .* - [F,L]
RewriteCond %{REMOTE_HOST} adm-muenchen\.de [NC,OR]
RewriteCond %{REMOTE_HOST} cyveillance\.com [NC,OR]
RewriteCond %{REMOTE_HOST} lightspeedsystems\.com [NC,OR]
RewriteCond %{REMOTE_HOST} pea016-29980-net-adsl-01\.altohiway\.com [NC,OR]
RewriteCond %{REMOTE_HOST} smartservercontrol\.com [NC,OR]
RewriteCond %{REMOTE_HOST} syntryx\.com [NC,OR]
RewriteCond %{REMOTE_HOST} proxad\.net [NC]
RewriteRule ^.*$ - [F]
RewriteCond %{HTTP_USER_AGENT} ^$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Custo [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^DISCo [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^eCatch [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^FlashGet [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^GetRight [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^GrabNet [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Grafula [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^HMView [NC,OR]
RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^InterGET [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Java [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^JetCar [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^larbin [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^lwp:: [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^lwp- [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Navroad [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^NearSite [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^NetAnts [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^NetSpider [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^NetZIP [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Octopus [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^pavuk [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^RealDownload [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^ReGet [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Schmozilla [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperBot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Surfbot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^WebAuto [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^WebCopier [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^webcollage [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^WebFetch [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^WebReaper [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^WebSauger [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^WebStripper [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^WebZIP [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Wget [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Widow [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeuse [NC]
RewriteRule ^.*$ - [F]

Bloquear "referrers" específicos. En este ejemplo se bloquea a1b2.com:
RewriteCond %{HTTP_REFERER} ^http://www.a1b2.com$
RewriteRule !^http://[^/.]\.tusitio\.com.* - [F,L]

Redirecciona lo que venga de "a1b2" a una imagen:
RewriteCond %{HTTP_REFERER} ^http://.*a1b2.*$ [NC]
RewriteRule .* http://www.tusitio/imagen.jpg [R]

Redirecciona el tráfico que viene de cierta dirección o rango de dirección a otra página:
RewriteCond %{REMOTE_ADDR} 192.168.10.*
RewriteRule .* http://www.tusitio.com/otrapagina.html [R]

Asignar permisos CHMOD automáticamente a tipos de archivos:
chmod .htpasswd files 640
chmod .htaccess files 644
chmod php files 600

Protección contra ataques DOS, limitando el tamaño de archivos que suben al server.
(10000000 bytes equivale a 10 megabytes). Esta línea es útil si permites que los usuarios de tu sitio suban archivos.
LimitRequestBody 10000000

Proteger directorios evitando la ejecución de scripts (edita las extensiones según lo requerido):
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI

Páginas de error personalizadas:
ErrorDocument 400 /errors/400.html
ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html

Autocorrección de pequeños errores de escritura:
<IfModule mod_speling.c>
CheckSpelling On
</IfModule>

Permitir al usuario descargar o abrir archivos multimedia (por lo general sólo se abren):
AddType application/octet-stream .avi
AddType application/octet-stream .mpg
AddType application/octet-stream .wmv
AddType application/octet-stream .mp3

Redireccionar visitantes a una dirección alternativa, menos a ti (modifica el IP):
ErrorDocument 403 http://www.sitio-alternativo.com
Order deny,allow
Deny from all
Allow from 200.105.77.66

Prevenir el acceso a un directorio a una hora u horas específicas:
# una hora
RewriteCond %{TIME_HOUR} ^12$
RewriteRule ^.*$ - [F,L]

# varias horas
RewriteCond %{TIME_HOUR} ^(12|13|14|15)$
RewriteRule ^.*$ - [F,L]

Redireccionar permanentemente www.sitio.com a sitio.com:
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www\.sitio\.com$ [NC]
RewriteRule ^(.*)$ http://sitio.com/$1 [R=301,L]

Redireccionar vieja página a la nueva:
RewriteEngine On
RewriteRule ^(.*)$ http://www.nueva.com/$1 [R=301,L]

Redirecionar el sitio vía 301:
redirect 301 / http://www.domain.com/

Redireccionar archivo específico vía 301:
redirect 301 /archivo.html http://www.domain.com/nuevo-archivo.html


Redireccionar sitio vía "permanent":
Redirect permanent / http://www.domain.com/

Redireccionar página o directorio vía "permanent":
Redirect permanent viejo-archivo.html http://www.domain.com/nuevo-archivo.html
Redirect permanent /viejo-directorio/ http://www.domain.com/nuevo-directorio/

Redireccionar archivo usando "RedirectMatch":
RedirectMatch 301 ^.*$ http://www.domain.com/index.html

Activar compresión
Se puede habilitar la compresión de datos inherente de PHP para ahorrar ancho de banda
<ifmodule mod_php4.c>
php_value zlib.output_compression 16386
</ifmodule>

No mostrar ‘www’
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www\.sitio\.com$ [NC]
RewriteRule ^(.*)$ http://sitio.com/$1 [R=301,L]

Evitando el error 500
Pasando el juego de caracteres se evita el mostrar un error 500
AddDefaultCharset utf-8