Foros del Web » Administración de Sistemas » Shared Hosting y VPS »

Problemas con Virsualhost redirect

Estas en el tema de Problemas con Virsualhost redirect en el foro de Shared Hosting y VPS en Foros del Web. Buenas noches tiempo sin escribir por aqui, tengo una duda espero me puedan ayudar. Necesito forzar todas las url de un sitio a cargar por ...
  #1 (permalink)  
Antiguo 06/11/2019, 21:27
Avatar de oscard41  
Fecha de Ingreso: mayo-2012
Ubicación: Caracas
Mensajes: 288
Antigüedad: 11 años, 10 meses
Puntos: 8
Problemas con Virsualhost redirect

Buenas noches tiempo sin escribir por aqui, tengo una duda espero me puedan ayudar.

Necesito forzar todas las url de un sitio a cargar por https pero necesito que solo una pueda cargar por http y no por https, el problema es que todas me cargar por https.

Aqui les muestro lo que tengo en codigo hasta ahora:

Código Apache:
Ver original
  1. <VirtualHost _default_:80>
  2.   ServerName www.dominio.com
  3.   ServerAlias dominio.com
  4.   Redirect permanent / https://www.dominio.com/
  5.  
  6.   Redirect 301 /https://dominio.com/json http://dominio.com/json
  7.   Redirect permanent /https://dominio.comr/json http://dominio.com/json

De ante mano muchas gracias
  #2 (permalink)  
Antiguo 07/11/2019, 08:23
 
Fecha de Ingreso: abril-2011
Mensajes: 170
Antigüedad: 12 años, 11 meses
Puntos: 68
Respuesta: Problemas con Virsualhost redirect

No te lo compliques. Es mucho más fácil con rewrites:

Código Apache:
Ver original
  1. RewriteEngine On
  2.  
  3. RewriteCond %{HTTPS} =off
  4. RewriteCond %{REQUEST_URI} !^/json/?
  5. RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]    
  6.  
  7. RewriteCond %{HTTPS} =on
  8. RewriteCond %{REQUEST_URI} ^/json/?
  9. RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]

El primer bloque redirige de http a https siempre que la ruta no sea /json.
El segundo bloque redirige de https a http solo en el caso de que la ruta sea /json.


Última edición por prueba230683; 07/11/2019 a las 11:47 Razón: corrección
  #3 (permalink)  
Antiguo 11/12/2019, 18:47
Avatar de oscard41  
Fecha de Ingreso: mayo-2012
Ubicación: Caracas
Mensajes: 288
Antigüedad: 11 años, 10 meses
Puntos: 8
Respuesta: Problemas con Virsualhost redirect

Muchas gracias por tu respuesta, hice la prueba y me funciona en un sitio web que hice desde cero pero en un sitio web hecho en wordpress no me esta funcionando, crees que las reglas que estan en el .htaccess actual me prelen la configuracion que ustd me envio?

asi quedo el .htaccess de la web

Código htaccess:
Ver original
  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3.  
  4. RewriteCond %{HTTPS} =off
  5. RewriteCond %{REQUEST_URI} !^/wp-json/?
  6. RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]    
  7.  
  8. RewriteCond %{HTTPS} =on
  9. RewriteCond %{REQUEST_URI} ^/wp-json/?
  10. RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]
  11. </IfModule>
  12.  
  13. <IfModule mod_rewrite.c>
  14. RewriteEngine On
  15. RewriteBase /
  16. RewriteCond %{HTTPS} on [OR]
  17. RewriteCond %{SERVER_PORT} ^443$ [OR]
  18. RewriteCond %{HTTP:X-Forwarded-Proto} https
  19. RewriteRule .* - [E=WPR_SSL:-https]
  20. RewriteCond %{HTTP:Accept-Encoding} gzip
  21. RewriteRule .* - [E=WPR_ENC:_gzip]
  22. RewriteCond %{REQUEST_METHOD} GET
  23. RewriteCond %{QUERY_STRING} =""
  24. RewriteCond %{HTTP:Cookie} !(wordpress_logged_in_.+|wp-postpass_|wptouch_switch_toggle|comment_author_|comment_author_email_) [NC]
  25. RewriteCond %{REQUEST_URI} !^(/(.+/)?feed/?|/(?:.+/)?embed/|/finalizar-compra/(.*)|/carrito/|/mi-cuenta/(.*)|/wc-api/v(.*)|/(index\.php/)?wp\-json(/.*|$))$ [NC]
  26. RewriteCond %{HTTP_USER_AGENT} !^(facebookexternalhit).* [NC]
  27. RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/wp-rocket/%{HTTP_HOST}%{REQUEST_URI}/index%{ENV:WPR_SSL}%{ENV:WPR_WEBP}.html%{ENV:WPR_ENC}" -f
  28. RewriteRule .* "/wp-content/cache/wp-rocket/%{HTTP_HOST}%{REQUEST_URI}/index%{ENV:WPR_SSL}%{ENV:WPR_WEBP}.html%{ENV:WPR_ENC}" [L]
  29.  
  30. </IfModule>
  31. # END WP Rocket
  32. # BEGIN WordPress
  33. <IfModule mod_rewrite.c>
  34. RewriteEngine On
  35. RewriteBase /
  36. RewriteRule ^index\.php$ - [L]
  37. RewriteCond %{REQUEST_FILENAME} !-f
  38. RewriteCond %{REQUEST_FILENAME} !-d
  39. RewriteRule . /index.php [L]
  40. </IfModule>

De ante mano muchas gracias por su respuesta
  #4 (permalink)  
Antiguo 12/12/2019, 06:03
 
Fecha de Ingreso: abril-2011
Mensajes: 170
Antigüedad: 12 años, 11 meses
Puntos: 68
Respuesta: Problemas con Virsualhost redirect

Efectivamente el código de WP te lo está reescribiendo, ya que RewriteRule se ejecuta en bucle hasta que ya no queden URLs por reescribir. Un truco para evitar esto es poner al principio de tu .htaccess lo siguiente:

Código Apache:
Ver original
  1. RewriteEngine On
  2. RewriteCond %{ENV:REDIRECT_STATUS} 200
  3. RewriteRule (.*) - [L]

Si la variable del entorno REDIRECT_STATUS es igual a 200, significa que ya se ha hecho una redirección, por tanto con RewriteRule (.*) - [L] le indicas que deje la URL como está, en lugar de seguir aplicando el resto de reglas que hay más abajo.

En tu caso quedaría así:

Código Apache:
Ver original
  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. RewriteCond %{ENV:REDIRECT_STATUS} 200
  4. RewriteRule (.*) - [L]
  5. </IfModule>
  6.  
  7. <IfModule mod_rewrite.c>
  8. RewriteEngine On
  9.  
  10. RewriteCond %{HTTPS} =off
  11. RewriteCond %{REQUEST_URI} !^/wp-json/?
  12. RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]    
  13.  
  14. RewriteCond %{HTTPS} =on
  15. RewriteCond %{REQUEST_URI} ^/wp-json/?
  16. RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]
  17. </IfModule>
  18.  
  19. <IfModule mod_rewrite.c>
  20. RewriteEngine On
  21. RewriteBase /
  22. RewriteCond %{HTTPS} on [OR]
  23. RewriteCond %{SERVER_PORT} ^443$ [OR]
  24. RewriteCond %{HTTP:X-Forwarded-Proto} https
  25. RewriteRule .* - [E=WPR_SSL:-https]
  26. RewriteCond %{HTTP:Accept-Encoding} gzip
  27. RewriteRule .* - [E=WPR_ENC:_gzip]
  28. RewriteCond %{REQUEST_METHOD} GET
  29. RewriteCond %{QUERY_STRING} =""
  30. RewriteCond %{HTTP:Cookie} !(wordpress_logged_in_.+|wp-postpass_|wptouch_switch_toggle|comment_author_|comment_author_email_) [NC]
  31. RewriteCond %{REQUEST_URI} !^(/(.+/)?feed/?|/(?:.+/)?embed/|/finalizar-compra/(.*)|/carrito/|/mi-cuenta/(.*)|/wc-api/v(.*)|/(index\.php/)?wp\-json(/.*|$))$ [NC]
  32. RewriteCond %{HTTP_USER_AGENT} !^(facebookexternalhit).* [NC]
  33. RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/wp-rocket/%{HTTP_HOST}%{REQUEST_URI}/index%{ENV:WPR_SSL}%{ENV:WPR_WEBP}.html%{ENV:WPR_ENC}" -f
  34. RewriteRule .* "/wp-content/cache/wp-rocket/%{HTTP_HOST}%{REQUEST_URI}/index%{ENV:WPR_SSL}%{ENV:WPR_WEBP}.html%{ENV:WPR_ENC}" [L]
  35.  
  36. </IfModule>
  37. # END WP Rocket
  38. # BEGIN WordPress
  39. <IfModule mod_rewrite.c>
  40. RewriteEngine On
  41. RewriteBase /
  42. RewriteRule ^index\.php$ - [L]
  43. RewriteCond %{REQUEST_FILENAME} !-f
  44. RewriteCond %{REQUEST_FILENAME} !-d
  45. RewriteRule . /index.php [L]
  46. </IfModule>

Un saludo

Etiquetas: redirect, server
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:40.