Hay 21 invitados en línea
Bienvenido, por favor ingrese sus datos o regístrese aquí
DWDpa es una comunidad dedicada al desarrollo y optimización de sitios Web      |      Requiere programaciòn especial para su sitio Web ?, Diseño Gráfico o simplemente crear su propia página Web ?, contáctenos      |      Posicionamiento Web en Google, el archivo .htaccess y otros temas te ayudarán a optimizar sitios Web

Manuales Posicionamiento Web Términos sobre Posicionamiento Posicionamiento Web en Google .htaccess Parámetros en .htaccess Directivas de .htaccess Joomla Manual de Instalación del Joomla Crear Templates para Joomla Migrar usuarios de Nuke a Joomla PHP-Nuke Instalación del PHP-Nuke en Español Cómo hacer tus propios Módulos Subir mi Portal y no morir en el intento Mis Primeros pasos con PHP-Nuke Configurar y Hacer tus Propios Bloques Base de Datos desde el FTP Tu Nuke Multilingüe Crear un Bloque con Scroll Cómo modificar un Theme Segundo rango para los Foros Cómo Hacer un Theme desde Cero Crear Menú Desplegable Rango en Lista de Miembros Crear un Precargador para Nuke Crear theme con archivos HTML Theme con bloques a la izquierda Theme: contenido con alto fijo Nuketips Adobe Photoshop Rejuvenecer Máscara Rápida Transformar de Foto a Dibujo Firmas con Adobe Photoshop Texto de fuego Desvanecimiento con Photoshop Efecto de Plástico Efecto de Aceite Animación con Image Ready Blast Burbuja Efecto Canica Cemento Mojado

Directivas de .htaccess Enviar 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


Views: 9511

Sea el primero en comentar el artículo

Solo los usuarios registrados pueden agregar sus comentarios.
Por favor, vaya a login, o regístrese.