Diferències

Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.

Enllaç a la visualització de la comparació

Ambdós costats versió prèvia Revisió prèvia
Següent revisió
Revisió prèvia
web:apache:htaccess:start [23/04/2020 10:26] – [zzxc.site] mateweb:apache:htaccess:start [20/06/2020 04:12] (actual) – [otros] admin
Línia 1: Línia 1:
-= .htacess, tutorial y ejemplos += .htaccess
-{{tag>wiki pendiente}}+
  
-/vía [[http://www.enespanol.com.ar/2006/04/03/tutorial-de-htaccess/]]+  * [[web:apache:htaccess:redirects]]
  
-<callout type="warning" title="REFACTORING" icon="true">reordenar las secciones</callout> +== basics
- +
-== tutorial+
   * 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 15: Línia 12:
     * [[https://httpd.apache.org/docs/2.4/expr.html]]     * [[https://httpd.apache.org/docs/2.4/expr.html]]
  
 +== acceso directorios
 === control de acceso a carpetas === control de acceso a carpetas
   * denegar acceso total a carpeta: <code apache>deny from all</code>   * denegar acceso total a carpeta: <code apache>deny from all</code>
Línia 32: Línia 30:
   * prevenir el listado de carpetas:<code apache>IndexIgnore *</code>   * prevenir el listado de carpetas:<code apache>IndexIgnore *</code>
  
 +
 +=== negar petición
 +niega cualquier conexión desde cualquier sitio
 +<code apache>
 +deny from all
 +</code>
 +
 +=== negar indices
 +no muestra listado de ficheros
 +<code apache>
 +Options -Indexes
 +Indexignore *
 +</code>
 +
 +== varios
 === activar compresión === activar compresión
   * activar compresión de datos inherente a PHP: <code apache>php_value zlib.output_compression 16386</code>   * activar compresión de datos inherente a PHP: <code apache>php_value zlib.output_compression 16386</code>
Línia 45: Línia 58:
   * que la página tenga más de 512 bytes para evitar la "funcionalidad" de Internet Explorer de sustituir por una página propia las que pesan menos de eso   * que la página tenga más de 512 bytes para evitar la "funcionalidad" de Internet Explorer de sustituir por una página propia las que pesan menos de eso
  
-=== bloquear referrer maliciosos (no hotlinking) 
-  * <code apache>RewriteEngine on 
-RewriteCond %{HTTP_REFERER} ejemplo\.com [NC,OR] 
-RewriteCond %{HTTP_REFERER} otroejemplo\.com 
-RewriteRule .* - [F]</code> 
-  * Si el visitante no es de mi sitio -example.com- y pide un fichero de esas extensiones, redireccionalo a un arhivo .gif :<code apache>RewriteEngine on 
-RewriteCond %{HTTP_REFERER} !^$ 
-RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?example\.com[NC] 
-RewriteRule .*\.(zip|mp3|avi|wmv|mpg|mpeg)$ http://www.example.com/images/nohotlink.gif [R,NC,L]</code> 
-  * 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:craftbot@yahoo.com [OR] 
-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] 
-</code> 
  
-== redirecciones 
-/via:[[http://deteresa.com/redireccion-301/]] 
-hay que tener el mod_rewrite activo 
-<code apache> 
-Options +FollowSymlinks 
-RewriteEngine on 
-</code> 
  
 +== otros
 +=== cambiar el fichero que abre o busca por defecto
 <code apache> <code apache>
-RedirectMatch permanent ^/(.*) http://<url>/$1+Directoryindex index.php index2.php
 </code> </code>
  
-== zzxc.site 
-<code apache> 
-RewriteEngine on 
-RewriteRule ^wiki.*$ https://miguelangel.torresegea.es/wiki/$1 [r=307,L] 
-RewriteRule ^blog.*$ https://miguelangel.torresegea.es/blog/$1 [r=307,L] 
-RewriteRule ^sqleditor.*$ https://miguelangel.torresegea.es/bike-9b12022-portable/ [r=307,L] 
-RewriteRule ^sql.*$ https://miguelangel.torresegea.es/sqldesigner/ [r=307,L] 
-RewriteRule ^estellar.*$ https://bitbucket.org/estellarcat/workspace/projects/EST [r=307,L] 
-RewriteRule ^diezminutos.*$ https://bitbucket.org/10minutos/workspace/projects/XMIN [r=307,L] 
-RewriteRule ^text.*$ https://www.outpan.com/app/e7d5b37405/mytextarea [r=307,L] 
- 
-RewriteCond %{HTTP_HOST} zxc.cat$ [NC] 
-RewriteCond %{REQUEST_URI} !^/help 
-RewriteRule ^(.*)$ https://miguelangel.torresegea.es/wiki/$1 [r=307,L] 
-</code> 
-=== 301 
-redireccionar de una página a otra u otro dominio: 
-<code apache> 
-Redirect 301 /vieja-pagina http://www.dominio.com/nueva-pagina 
-</code> 
- 
-redireccionar solo la página principal del dominio: 
-<code apache> 
-RedirectMatch 301 ^/$ http://www.dominio.com/nueva-pagina 
-</code> 
- 
-redireccionar un directorio: 
-<code apache> 
-Redirect 301 /viejo-directorio/ http://www.dominio.com/nuevo-directorio/ 
-</code> 
- 
-redirección de un subdirectorio + sus páginas: 
-<code apache> 
-RedirectMatch 301 ^/viejo-directorio/(.*)$ http://www.dominio.com/nueva-pagina 
-</code> 
- 
-redireccionar dominio 
-<code apache> 
-Redirect 301 / http://www.dominio.com 
-</code> 
-<code apache> 
-RedirectMatch 301 ^(.*)$ http://www.dominio.com 
-</code> 
- 
-Redireccionar 301 (de técnicos de Colt) 
-<code apache> 
-RewriteEngine on 
-rewriterule ^(.*)$ http://www.volvocars.com/es/sales-services/sales/volvoselekt/Pages/ [r=301,nc] 
-</code> 
- 
-=== rewrites 
-redireccionar de www a no-www: 
-<code apache> 
-<IfModule mod_rewrite.c> 
-   RewriteCond %{HTTP_HOST} ^example.com [NC] 
-   RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 
-</IfModule> 
-</code> 
- 
-redireccionar de no-www a www 
-<code apache> 
-<IfModule mod_rewrite.c> 
-  RewriteCond %{HTTP_HOST} ^www.example.com [NC] 
-  RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] 
-</IfModule> 
-</code> 
-Más información: http://deteresa.com/redireccion-301 
- 
-eliminar las www: 
-<code apache> 
-Options +FollowSymlinks 
-RewriteEngine on 
-RewriteCond %{http_host} ^www\.example\.com[nc] 
-RewriteRule ^(.*)$ http://example.com/$1 [r=301,nc] 
-</code> 
- 
-<code apache> 
-RewriteEngine On 
-RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
-RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
-</code> 
- 
-cancelar sitio completo "por obras": 
-<code apache> 
-RewriteEngine On 
-RewriteBase / 
-RewriteCond %{HTTP_COOKIE} !^.*secret-cookie.*$ [NC] 
-RewriteRule .* maintenance-page.html [NC,L] 
-</code> 
- 
-/vía: [[http://www.besthostratings.com/articles/force-ssl-htaccess.html]] 
-utilizar la redirección 301 para evitar penalización en Google: 
-<code apache> 
-Options +FollowSymlinks 
-RewriteEngine on 
-rewriterule ^(.*)$ http://www.nuevapaginaweb.com/$1 [r=301,nc] 
-</code> 
- 
-<code php> 
-<?php 
-$web_url ="http://www.nuevapaginaweb.com"; 
-header("HTTP/1.1 301 Moved Permanently"); 
-header("Location: $web_url"); 
-exit(0); 
-?> 
-</code> 
- 
-redirección http a https: 
-activar el módulo //rewrite// en apache 
-<code> 
-$ sudo a2enmod rewrite 
-</code> 
-<code> 
-# 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://www.dominio.com/$1 [R,L] 
- 
-# Para forzar la conexión segura en un folder en especifico. 
-RewriteEngine On 
-RewriteCond %{SERVER_PORT} 80 
-RewriteCond %{REQUEST_URI} folder 
-RewriteRule ^(.*)$ https://www.dominio.com/folder/$1 [R,L] 
-Para este segundo caso el archivo .htaccess debe estar ubicado en el folder donde necesitas activar HTTPS. 
-</code> 
- 
-de www. a <nada> para evitar penalizaciones de doble indexación: 
-<code apache> 
-RewriteEngine On 
-RewriteCond% {} HTTP_HOST! ^ su-site.com $ [NC] 
-RewriteRule ^(.*)$ http://your-site.com/ $ 1 [L, R = 301] 
-</code> 
- 
-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} !^/copadelrey/ 
-RewriteRule (.*) /copadelrey/ [L] 
-</code> 
-en este caso, las peticiones a www.entregaelbalon.com irán automaticamente a www.entregaelbalon.com/copadelrey (si se intenta con redirect da bucle) 
- 
-== 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 301: Línia 74:
 </code> </code>
  
-=== 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://httpd.apache.org/docs/2.2/howto/ssi.html]] [[http://httpd.apache.org/docs/2.2/howto/ssi.html]]
Línia 329: Línia 102:
 debe estar habilitado el ''auth_digest.load'' en ''/etc/apache2/mods-enabled'' debe estar habilitado el ''auth_digest.load'' en ''/etc/apache2/mods-enabled''
 <code apache> <code apache>
-</code> 
-== negar petición 
-niega cualquier conexión desde cualquier sitio 
-<code apache> 
-deny from all 
 </code> </code>
  
-== negar indices 
-no muestra listado de ficheros 
-<code apache> 
-Options -Indexes 
-Indexignore * 
-</code> 
  
-== cambiar el fichero que abre o busca por defecto 
-<code apache> 
-Directoryindex index.php index2.php 
-</code> 
  
  
-== redireccions 
-<code; .htaccess> 
-RewriteEngine on 
-rewriterule ^(.*)coneixelteucervell(.*)$ https://fidmag.org/ca/subwebs/participa-i-descobreix-el-teu-cervell.html [r=301,nc] 
-rewriterule ^(.*)$ https://fidmag.org/es/subwebs-esp/participa-y-descubre-tu-cerebro.html [r=301,nc] 
-</code> 
-  * redirecció en fitxer configuració virtualhost de :80 a :443 
-<code> 
-<VirtualHost *:80> 
-    ServerName landing.fidmag.org 
-    Redirect permanent / https://landing.fidmag.org/ 
-</VirtualHost> 
- 
-<VirtualHost *:80> 
-    ServerName brainpredict.com 
-    ServerAlias www.brainpredict.com  
-    Redirect permanent / https://brainpredict.com/ 
-</VirtualHost> 
- 
-<VirtualHost *:443> 
-    ServerAdmin webmaster@localhost 
-    ServerName landing.fidmag.org 
-    ServerAlias braindredict.com 
- 
-    DocumentRoot /var/landing.fidmag.org/public 
-    <Directory /var/landing.fidmag.org/public> 
-        #Options -Indexes 
-        Options FollowSymLinks Indexes 
-        AllowOverride All 
-        Require all granted 
-    </Directory> 
- 
-    ErrorLog /var/landing.fidmag.org/log/error.log 
-    CustomLog /var/landing.fidmag.org/log/access.log combined 
- 
-    SSLEngine on 
-    SSLCertificateFile  /etc/letsencrypt/live/landing.fidmag.org/ssl.pem 
- 
-    <FilesMatch "\.(cgi|shtml|phtml|php)$"> 
-            SSLOptions +StdEnvVars 
-    </FilesMatch> 
-    <Directory /usr/lib/cgi-bin> 
-            SSLOptions +StdEnvVars 
-    </Directory> 
-</VirtualHost> 
-</code> 
  
-== fuentes 
-[[http://www.youtube.com/watch?v=BM9tV903b6o|]] 
  
  • web/apache/htaccess/start.1587662773.txt.gz
  • Darrera modificació: 23/04/2020 10:26
  • per mate