使用mod_rewrite和IBM http服务器从http到https再到http的转换方式

3

好的,我有一个apache IBM HTTP Server WAS 6.1的设置。

我的证书已正确安装,并且可以成功加载httphttps页面。

通过https进行成功的j_security_check身份验证后,我希望现在授权的页面(以及所有后续页面)加载为http

我希望这一切都能与mod_rewrite一起工作,因为我不想为了应该在Web服务器上简单实现的事情而更改应用程序代码。

我认为这应该可行,但它并不起作用,我担心是因为j_security_check以某种方式绕过了mod_rewrite

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

我知道 [R,L] 会强制执行规则作为请求中最后一个运行的规则,并相应地进行重定向。
我在谷歌上搜索一番后发现了这个小技巧。
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>

将继承声明添加到指向机器IP和端口443的单个虚拟主机声明中并没有帮助解决问题。现在我知道我的应用服务器分别在9080和9443上通信,但是我找不到一个在httpd.conf文件中的虚拟主机。在未经身份验证的情况下,我进行了一些使用不同重写规则的测试,并发现我的mod rewrite代码可以工作。那么,我该如何让WebSphere在身份验证后使用mod rewrite呢?就像Web服务器仅用于未经身份验证的请求一样,之后某个黑盒容器以某种方式提供所有内容。
2个回答

0

这是关于 HTTP 到 HTTPS 再到 HTTP 的解决方案。

你需要像文章中所述,在虚拟主机中设置条件和重写规则,但由于某种原因继承并未生效。

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>

-1
猜测一下:第二个逻辑或应该是一个与(即没有[OR],而RewriteCond默认为AND)?
RewriteCond %{THE_REQUEST} !login\.jsp.*action=init
RewriteCond %{THE_REQUEST} !login\.jsp.*action=submit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接