http a https a http usando mod_rewrite y el servidor http de IBM
-
05-07-2019 - |
Pregunta
Ok, tengo una configuración de apache IBM HTTP Server WAS 6.1
Tengo mis certs
correctamente instalados y puedo cargar correctamente las páginas de http
y https
.
Después de una autenticación j_security_check
exitosa a través de https
, quiero que la página ahora autorizada (y todas las páginas subsiguientes) se cargue como http
.
Quiero que todo esto funcione con mod_rewrite
porque no quiero cambiar el código de la aplicación por algo que realmente debería ser fácil de hacer en el servidor web.
Pensaría que esto funcionaría, pero no lo hace y me temo que se deba a que j_security_check
pasa por alto mod_rewrite
de alguna manera.
RewriteCond %{HTTPS} =off
RewriteCond %{THE_REQUEST} login\.jsp.*action=init [OR]
RewriteCond %{THE_REQUEST} login\.jsp.*action=submit
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L] <<-- this rule is working
RewriteCond %{HTTPS} =on
RewriteCond %{THE_REQUEST} !login\.jsp.*action=init [OR]
RewriteCond %{THE_REQUEST} !login\.jsp.*action=submit
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R,L] <--- this rule is not working or the condition is not returning true
Sé que [R, L]
forzará que la regla ejecutada sea la última regla que se ejecute en una solicitud y redirija en consecuencia.
Encontré esta pequeña joya después de un poco de google.
mod_rewrite: My rules are ignored. Nothing is written to the rewrite log.
The most common cause of this is placing mod_rewrite directives at global scope (outside of any VirtualHost containers) but expecting the directives to apply to requests which were matched by a VirtualHost container.
In this example, the mod_rewrite configuration will be ignored for requests which are received on port 443:
RewriteEngine On
RewriteRule ^index.htm$ index.html
<VirtualHost *:443>
existing vhost directives
</VirtualHost>
Unlike most configurable features, the mod_rewrite configuration is not inherited by default within a <VirtualHost > container. To have global mod_rewrite directives apply to a VirtualHost, add these two extra directives to the VirtualHost container:
<VirtualHost *:443>
existing vhost directives
RewriteEngine On
RewriteOptions Inherit
</VirtualHost>
Agregar la declaración Heredar a mi declaración única virtualhost
que apunta a la ip de la máquina y al puerto 443
no ayudó en nada.
Ahora sé que mi servidor de aplicaciones se comunica en 9080
y 9443
respectivamente, pero no puedo encontrar un solo virtualhost
en el servidor web httpd.conf
.
Hice algunas pruebas con diferentes reglas de reescritura mientras no estaba autenticado y vi que mi código mod rewrite
funcionó ...
Entonces: ¿cómo puedo hacer que websphere use reescritura mod después de la autenticación?
Es como si el servidor web solo se usara para solicitudes no autenticadas y después de eso, algún contenedor de Blackbox sirve todo de alguna manera.
Solución
Esta es la solución para http a https to http
Tienes que poner la condición y la regla de reescritura en el host virtual como dijo el artículo de arco, pero por algún motivo, la herencia no quería trabajar.
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /path/login\.jsp\ HTTP/1\.1
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
<VirtualHost 000.000.000.000:443>
ServerName servername
ServerAlias url.com machinename
DocumentRoot d:/ibmhttpserver61/htdocs/en_US
ErrorLog d:/ibmhttpserver61/logs/secerr.log
TransferLog d:/ibmhttpserver61/logs/sectrans.log
SSLEnable
Keyfile d:/ibmhttpserver61/ssl/ctxroot.kdb
SSLV2Timeout 100
SSLV3Timeout 1000
RewriteEngine On
RewriteCond %{REQUEST_URI} /path/secure/index.jsf
RewriteRule ^(.*)$ http://url/path/secure/index.jsf [R,L]
</VirtualHost>
Otros consejos
Conjetura alocada: ¿debería el segundo OR lógico ser un AND (es decir, no [OR] y el RewriteCond tiene como valor predeterminado el AND)?
RewriteCond %{THE_REQUEST} !login\.jsp.*action=init
RewriteCond %{THE_REQUEST} !login\.jsp.*action=submit