Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
| Següent revisió | Revisió prèvia | ||
| web:apache:htaccess:redirects [20/06/2020 03:52] – creat admin | web:apache:htaccess:redirects [05/02/2022 03:29] (actual) – [zxc.cat] mate | ||
|---|---|---|---|
| Línia 1: | Línia 1: | ||
| - | = rewrites (redirecciones) | + | = .htaccess |
| / | / | ||
| hay que tener el mod_rewrite activo | hay que tener el mod_rewrite activo | ||
| Línia 21: | Línia 21: | ||
| RewriteRule ^diezminutos.*$ https:// | RewriteRule ^diezminutos.*$ https:// | ||
| RewriteRule ^text.*$ https:// | RewriteRule ^text.*$ https:// | ||
| + | RewriteRule ^k1.*$ https:// | ||
| + | RewriteRule ^montmany.*$ https:// | ||
| RewriteCond %{HTTP_HOST} zxc.cat$ [NC] | RewriteCond %{HTTP_HOST} zxc.cat$ [NC] | ||
| RewriteCond %{REQUEST_URI} !^/help | RewriteCond %{REQUEST_URI} !^/help | ||
| + | RewriteCond %{REQUEST_URI} !^/ | ||
| RewriteRule ^(.*)$ https:// | RewriteRule ^(.*)$ https:// | ||
| </ | </ | ||
| == 301 | == 301 | ||
| - | redireccionar de una página a otra u otro dominio: | + | * redireccionar de una página a otra u otro dominio:< |
| - | <code apache> | + | |
| Redirect 301 / | Redirect 301 / | ||
| </ | </ | ||
| - | + | * redireccionar solo la página principal del dominio:< | |
| - | redireccionar solo la página principal del dominio: | + | |
| - | <code apache> | + | |
| RedirectMatch 301 ^/$ http:// | RedirectMatch 301 ^/$ http:// | ||
| </ | </ | ||
| - | + | * redireccionar un directorio:< | |
| - | redireccionar un directorio: | + | |
| - | <code apache> | + | |
| Redirect 301 / | Redirect 301 / | ||
| </ | </ | ||
| - | + | * redirección de un subdirectorio + sus páginas:< | |
| - | redirección de un subdirectorio + sus páginas: | + | |
| - | <code apache> | + | |
| RedirectMatch 301 ^/ | RedirectMatch 301 ^/ | ||
| </ | </ | ||
| - | + | * redireccionar dominio< | |
| - | redireccionar dominio | + | |
| - | <code apache> | + | |
| Redirect 301 / http:// | Redirect 301 / http:// | ||
| - | </ | + | </ |
| - | <code apache> | + | |
| RedirectMatch 301 ^(.*)$ http:// | RedirectMatch 301 ^(.*)$ http:// | ||
| </ | </ | ||
| - | + | * Redireccionar 301 (de técnicos de Colt): <code apache> | |
| - | Redireccionar 301 (de técnicos de Colt) | + | |
| - | <code apache> | + | |
| RewriteEngine on | RewriteEngine on | ||
| rewriterule ^(.*)$ http:// | rewriterule ^(.*)$ http:// | ||
| </ | </ | ||
| - | redireccionar de www a no-www: | + | == www |
| - | <code apache> | + | * redireccionar de www a no-www:< |
| < | < | ||
| | | ||
| Línia 69: | Línia 60: | ||
| </ | </ | ||
| </ | </ | ||
| - | + | * redireccionar de no-www a www:<code apache> | |
| - | redireccionar de no-www a www | + | |
| - | <code apache> | + | |
| < | < | ||
| RewriteCond %{HTTP_HOST} ^www.example.com [NC] | RewriteCond %{HTTP_HOST} ^www.example.com [NC] | ||
| Línia 78: | Línia 67: | ||
| </ | </ | ||
| Más información: | Más información: | ||
| - | + | * eliminar las www:< | |
| - | eliminar las www: | + | |
| - | <code apache> | + | |
| Options +FollowSymlinks | Options +FollowSymlinks | ||
| RewriteEngine on | RewriteEngine on | ||
| RewriteCond %{http_host} ^www\.example\.com[nc] | RewriteCond %{http_host} ^www\.example\.com[nc] | ||
| RewriteRule ^(.*)$ http:// | RewriteRule ^(.*)$ http:// | ||
| - | </ | + | </ |
| - | + | ||
| - | <code apache> | + | |
| RewriteEngine On | RewriteEngine On | ||
| RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] | RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] | ||
| RewriteRule ^(.*)$ http:// | RewriteRule ^(.*)$ http:// | ||
| </ | </ | ||
| - | + | * de www. a < | |
| - | cancelar sitio completo "por obras": | + | |
| - | <code apache> | + | |
| RewriteEngine On | RewriteEngine On | ||
| - | RewriteBase / | + | RewriteCond% {} HTTP_HOST! ^ su-site.com $ [NC] |
| - | RewriteCond %{HTTP_COOKIE} !^.*secret-cookie.*$ [NC] | + | RewriteRule |
| - | RewriteRule .* maintenance-page.html [NC,L] | + | |
| </ | </ | ||
| - | /vía: [[http:// | + | == http a https |
| - | 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 | + | |
| - | activar el módulo //rewrite// en apache | + | |
| - | < | + | |
| $ sudo a2enmod rewrite | $ sudo a2enmod rewrite | ||
| - | </ | + | </ |
| - | < | + | |
| # Copia el contenido siguiente en tu archivo .htaccess y colócalo en la raíz de tu sitio web. | # Copia el contenido siguiente en tu archivo .htaccess y colócalo en la raíz de tu sitio web. | ||
| RewriteEngine On | RewriteEngine On | ||
| Línia 137: | Línia 100: | ||
| </ | </ | ||
| - | de www. a < | + | == otros |
| - | <code apache> | + | * cancelar sitio completo "por obras": |
| RewriteEngine On | RewriteEngine On | ||
| - | RewriteCond% {} HTTP_HOST! ^ su-site.com $ [NC] | + | RewriteBase / |
| - | RewriteRule | + | RewriteCond %{HTTP_COOKIE} !^.*secret-cookie.*$ [NC] |
| + | RewriteRule .* maintenance-page.html [NC,L] | ||
| </ | </ | ||
| - | + | /vía: [[http:// | |
| - | redireccionar una petición de la raiz de la página web a una carpeta: | + | * utilizar la redirección 301 para evitar penalización en Google:< |
| - | <code apache> | + | Options +FollowSymlinks |
| + | RewriteEngine on | ||
| + | rewriterule ^(.*)$ http:// | ||
| + | </ | ||
| + | * en PHP:< | ||
| + | <?php | ||
| + | $web_url =" | ||
| + | header(" | ||
| + | header(" | ||
| + | exit(0); | ||
| + | ?> | ||
| + | </ | ||
| + | | ||
| RewriteEngine On | RewriteEngine On | ||
| RewriteCond %{HTTP_HOST} ^entregaelbalon\.com$ [OR] | RewriteCond %{HTTP_HOST} ^entregaelbalon\.com$ [OR] | ||
| Línia 153: | Línia 129: | ||
| </ | </ | ||
| en este caso, las peticiones a www.entregaelbalon.com irán automáticamente a www.entregaelbalon.com/ | en este caso, las peticiones a www.entregaelbalon.com irán automáticamente a www.entregaelbalon.com/ | ||
| + | |||
| + | == redireccions | ||
| + | <code; .htaccess> | ||
| + | RewriteEngine on | ||
| + | rewriterule ^(.*)coneixelteucervell(.*)$ https:// | ||
| + | rewriterule ^(.*)$ https:// | ||
| + | </ | ||
| + | * redirecció en fitxer configuració virtualhost de :80 a :443 | ||
| + | < | ||
| + | < | ||
| + | ServerName landing.fidmag.org | ||
| + | Redirect permanent / https:// | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | ServerName brainpredict.com | ||
| + | ServerAlias www.brainpredict.com | ||
| + | Redirect permanent / https:// | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | ServerAdmin webmaster@localhost | ||
| + | ServerName landing.fidmag.org | ||
| + | ServerAlias braindredict.com | ||
| + | |||
| + | DocumentRoot / | ||
| + | < | ||
| + | #Options -Indexes | ||
| + | Options FollowSymLinks Indexes | ||
| + | AllowOverride All | ||
| + | Require all granted | ||
| + | </ | ||
| + | |||
| + | ErrorLog / | ||
| + | CustomLog / | ||
| + | |||
| + | SSLEngine on | ||
| + | SSLCertificateFile | ||
| + | |||
| + | < | ||
| + | SSLOptions +StdEnvVars | ||
| + | </ | ||
| + | < | ||
| + | SSLOptions +StdEnvVars | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | == 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 | ||