Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
| Ambdós costats versió prèvia Revisió prèvia Següent revisió | Revisió prèvia | ||
| web:apache:htaccess:start [04/07/2019 01:57] – [tutorial] mate | web:apache:htaccess:start [20/06/2020 04:12] (actual) – [otros] admin | ||
|---|---|---|---|
| Línia 1: | Línia 1: | ||
| - | = .htacess, tutorial y ejemplos | + | = .htaccess |
| - | {{tag> | + | |
| - | /vía [[http:// | + | |
| - | <callout type=" | + | * [[web: |
| - | == tutorial | + | == basics |
| * mantén el fichero .htaccess tan pequeño como pueda ser | * mantén el fichero .htaccess tan pequeño como pueda ser | ||
| * comenta y organiza correctamente el fichero .htaccess | * comenta y organiza correctamente el fichero .htaccess | ||
| Línia 14: | Línia 12: | ||
| * [[https:// | * [[https:// | ||
| + | == acceso directorios | ||
| === control de acceso a carpetas | === control de acceso a carpetas | ||
| * denegar acceso total a carpeta: <code apache> | * denegar acceso total a carpeta: <code apache> | ||
| Línia 31: | Línia 30: | ||
| * prevenir el listado de carpetas:< | * prevenir el listado de carpetas:< | ||
| + | |||
| + | === negar petición | ||
| + | niega cualquier conexión desde cualquier sitio | ||
| + | <code apache> | ||
| + | deny from all | ||
| + | </ | ||
| + | |||
| + | === negar indices | ||
| + | no muestra listado de ficheros | ||
| + | <code apache> | ||
| + | Options -Indexes | ||
| + | Indexignore * | ||
| + | </ | ||
| + | |||
| + | == varios | ||
| === activar compresión | === activar compresión | ||
| * activar compresión de datos inherente a PHP: <code apache> | * activar compresión de datos inherente a PHP: <code apache> | ||
| Línia 44: | Línia 58: | ||
| * que la página tenga más de 512 bytes para evitar la " | * que la página tenga más de 512 bytes para evitar la " | ||
| - | === bloquear referrer maliciosos (no hotlinking) | ||
| - | * <code apache> | ||
| - | RewriteCond %{HTTP_REFERER} ejemplo\.com [NC,OR] | ||
| - | RewriteCond %{HTTP_REFERER} otroejemplo\.com | ||
| - | RewriteRule .* - [F]</ | ||
| - | * Si el visitante no es de mi sitio -example.com- y pide un fichero de esas extensiones, | ||
| - | RewriteCond %{HTTP_REFERER} !^$ | ||
| - | RewriteCond %{HTTP_REFERER} !^http:// | ||
| - | RewriteRule .*\.(zip|mp3|avi|wmv|mpg|mpeg)$ http:// | ||
| - | * ojo con enlaces que si que quieres permitir - como un RSS - a alguno de tus ficheros | ||
| - | === bloqueo de robots maliciosos | ||
| - | <code apache> | ||
| - | RewriteEngine On | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto: | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Custo [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^HMView [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^larbin [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Wget [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Widow [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR] | ||
| - | RewriteCond %{HTTP_USER_AGENT} ^Zeus | ||
| - | RewriteRule .* - [F] | ||
| - | </ | ||
| - | == redirecciones | ||
| - | / | ||
| - | hay que tener el mod_rewrite activo | ||
| - | < | ||
| - | Options +FollowSymlinks | ||
| - | RewriteEngine on | ||
| - | </ | ||
| - | < | + | == otros |
| - | RedirectMatch permanent ^/(.*) http://< | + | === cambiar el fichero que abre o busca por defecto |
| - | </ | + | |
| - | === 301 | + | |
| - | redireccionar de una página a otra u otro dominio: | + | |
| <code apache> | <code apache> | ||
| - | Redirect 301 / | + | Directoryindex index.php index2.php |
| </ | </ | ||
| - | redireccionar solo la página principal del dominio: | ||
| - | <code apache> | ||
| - | RedirectMatch 301 ^/$ http:// | ||
| - | </ | ||
| - | |||
| - | redireccionar un directorio: | ||
| - | <code apache> | ||
| - | Redirect 301 / | ||
| - | </ | ||
| - | |||
| - | redirección de un subdirectorio + sus páginas: | ||
| - | <code apache> | ||
| - | RedirectMatch 301 ^/ | ||
| - | </ | ||
| - | |||
| - | redireccionar dominio | ||
| - | <code apache> | ||
| - | Redirect 301 / http:// | ||
| - | </ | ||
| - | <code apache> | ||
| - | RedirectMatch 301 ^(.*)$ http:// | ||
| - | </ | ||
| - | |||
| - | Redireccionar 301 (de técnicos de Colt) | ||
| - | <code apache> | ||
| - | RewriteEngine on | ||
| - | rewriterule ^(.*)$ http:// | ||
| - | </ | ||
| - | |||
| - | === rewrites | ||
| - | redireccionar de www a no-www: | ||
| - | <code apache> | ||
| - | < | ||
| - | | ||
| - | | ||
| - | </ | ||
| - | </ | ||
| - | |||
| - | redireccionar de no-www a www | ||
| - | <code apache> | ||
| - | < | ||
| - | RewriteCond %{HTTP_HOST} ^www.example.com [NC] | ||
| - | RewriteRule ^(.*)$ http:// | ||
| - | </ | ||
| - | </ | ||
| - | Más información: | ||
| - | |||
| - | eliminar las www: | ||
| - | <code apache> | ||
| - | Options +FollowSymlinks | ||
| - | RewriteEngine on | ||
| - | RewriteCond %{http_host} ^www\.example\.com[nc] | ||
| - | RewriteRule ^(.*)$ http:// | ||
| - | </ | ||
| - | |||
| - | <code apache> | ||
| - | RewriteEngine On | ||
| - | RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] | ||
| - | RewriteRule ^(.*)$ http:// | ||
| - | </ | ||
| - | |||
| - | cancelar sitio completo "por obras": | ||
| - | <code apache> | ||
| - | RewriteEngine On | ||
| - | RewriteBase / | ||
| - | RewriteCond %{HTTP_COOKIE} !^.*secret-cookie.*$ [NC] | ||
| - | RewriteRule .* maintenance-page.html [NC,L] | ||
| - | </ | ||
| - | |||
| - | /vía: [[http:// | ||
| - | utilizar la redirección 301 para evitar penalización en Google: | ||
| - | <code apache> | ||
| - | Options +FollowSymlinks | ||
| - | RewriteEngine on | ||
| - | rewriterule ^(.*)$ http:// | ||
| - | </ | ||
| - | |||
| - | <code php> | ||
| - | <?php | ||
| - | $web_url =" | ||
| - | header(" | ||
| - | header(" | ||
| - | exit(0); | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | redirección http a https: | ||
| - | activar el módulo //rewrite// en apache | ||
| - | < | ||
| - | $ sudo a2enmod rewrite | ||
| - | </ | ||
| - | < | ||
| - | # Copia el contenido siguiente en tu archivo .htaccess y colócalo en la raíz de tu sitio web. | ||
| - | RewriteEngine On | ||
| - | RewriteCond %{SERVER_PORT} 80 | ||
| - | RewriteRule ^(.*)$ https:// | ||
| - | |||
| - | # Para forzar la conexión segura en un folder en especifico. | ||
| - | RewriteEngine On | ||
| - | RewriteCond %{SERVER_PORT} 80 | ||
| - | RewriteCond %{REQUEST_URI} folder | ||
| - | RewriteRule ^(.*)$ https:// | ||
| - | Para este segundo caso el archivo .htaccess debe estar ubicado en el folder donde necesitas activar HTTPS. | ||
| - | </ | ||
| - | |||
| - | de www. a < | ||
| - | <code apache> | ||
| - | RewriteEngine On | ||
| - | RewriteCond% {} HTTP_HOST! ^ su-site.com $ [NC] | ||
| - | RewriteRule ^(.*)$ http:// | ||
| - | </ | ||
| - | |||
| - | redireccionar una petición de la raiz de la página web a una carpeta: | ||
| - | <code apache> | ||
| - | RewriteEngine On | ||
| - | RewriteCond %{HTTP_HOST} ^entregaelbalon\.com$ [OR] | ||
| - | RewriteCond %{HTTP_HOST} ^www\.entregaelbalon\.com$ | ||
| - | RewriteCond %{REQUEST_URI} !^/ | ||
| - | RewriteRule (.*) / | ||
| - | </ | ||
| - | en este caso, las peticiones a www.entregaelbalon.com irán automaticamente a www.entregaelbalon.com/ | ||
| - | |||
| - | == otros | ||
| === esconder la extensión del lenguaje de scripting | === esconder la extensión del lenguaje de scripting | ||
| es necesario renombrar los ficheros a la nueva extensión | es necesario renombrar los ficheros a la nueva extensión | ||
| Línia 284: | Línia 74: | ||
| </ | </ | ||
| - | === server side includes | + | == server side includes |
| permite contenido dinámico dentro de páginas estáticas que se intepretan por el servidor | permite contenido dinámico dentro de páginas estáticas que se intepretan por el servidor | ||
| [[http:// | [[http:// | ||
| Línia 312: | Línia 102: | ||
| debe estar habilitado el '' | debe estar habilitado el '' | ||
| <code apache> | <code apache> | ||
| - | </ | ||
| - | == negar petición | ||
| - | niega cualquier conexión desde cualquier sitio | ||
| - | <code apache> | ||
| - | deny from all | ||
| </ | </ | ||
| - | == negar indices | ||
| - | no muestra listado de ficheros | ||
| - | <code apache> | ||
| - | Options -Indexes | ||
| - | Indexignore * | ||
| - | </ | ||
| - | == cambiar el fichero que abre o busca por defecto | ||
| - | <code apache> | ||
| - | Directoryindex index.php index2.php | ||
| - | </ | ||
| - | == fuentes | ||
| - | [[http:// | ||
| - | {{tag> servers}} | + | |