使用隐式重定向的 Apache 重写
一段时间以来我一直在尝试这样做,但没有成功。 我会提前说,这可能是一个新手问题,所以很抱歉,但我确实需要一些帮助。
我正在尝试将 cgi-bin/java-rmi.cgi 的请求重定向到 tomcat 上的 servlet(来自 apache)。 我已成功重定向到 servlet,但无法执行隐式重定向(对客户端隐藏 url 更改)。
这是强制性的,因为如果重定向,rmi 将无法工作,所以我必须向客户端隐藏它。
现在我的 httpd.conf 看起来像这样(显然只有相关的东西)
RewriteEngine on
RewriteLog logs/rewrite.log
RewriteLogLevel 9
RewriteRule ^/cgi-bin/java\-rmi\.cgi http://localhost/RMIServlet [P]
Alias /RMIServlet "C:/Program Files (x86)/Apache Software Foundation/Tomcat 6.0/webapps/RMIServlet"
<Directory "C:/Program Files (x86)/Apache Software Foundation/Tomcat 6.0/webapps/RMIServlet/">
Options Indexes FollowSymLinks
</Directory>
include "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/mod_jk.conf"
另外,我的 mod_jk.conf 看起来像这样(同样,只有相关的东西)
# Send everything!! to worker ajp13
JkMount / ajp13
JkMount /* ajp13
(虽然我认为 mod_jk.conf 与问题无关)
我也启用了这些:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module mo
dules/mod_rewrite.so
每当我尝试打开 http://localhost/cgi-bin/ java-rmi.cgi 页面以 url http://localhost/RMIServlet 打开,这不好。
我究竟做错了什么?
谢谢!
I've been trying to do this for some time unsuccesfully.
I'll say in advance that this is probably a newbie question so apologies but I do need some assistance with this.
I am trying to redirect requests to cgi-bin/java-rmi.cgi to a servlet on tomcat (from apache).
I've managed to redirect to the servlet successfully but I have not been able to do an implicit redirections (hiding the url change from the client).
This is mandetory since rmi will not work if it is redirected so I have to hide this from the client.
Right now my httpd.conf looks like this (only the relevant stuff obviously)
RewriteEngine on
RewriteLog logs/rewrite.log
RewriteLogLevel 9
RewriteRule ^/cgi-bin/java\-rmi\.cgi http://localhost/RMIServlet [P]
Alias /RMIServlet "C:/Program Files (x86)/Apache Software Foundation/Tomcat 6.0/webapps/RMIServlet"
<Directory "C:/Program Files (x86)/Apache Software Foundation/Tomcat 6.0/webapps/RMIServlet/">
Options Indexes FollowSymLinks
</Directory>
include "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/mod_jk.conf"
additionally, my mod_jk.conf looks like this (again, only relevant stuff)
# Send everything!! to worker ajp13
JkMount / ajp13
JkMount /* ajp13
(although I presume mod_jk.conf has nothing to do with the problem)
I also enabled these:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module mo
dules/mod_rewrite.so
Whenever I try to open http://localhost/cgi-bin/java-rmi.cgi the page opens with the url http://localhost/RMIServlet which is not good.
What am I doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Dav 错误,使用 [P] 替换需要是合格的 URI,包括协议和主机名。
Dav 错误
mod_proxy 是否真的处于活动状态并且配置正确? 抱歉,我无法帮助您,因为我还没有使用过此操作。
在重写 URL 之前尝试定义 RMIServlet。
也许在您的规则之后正在进行另一次重写,请尝试为最后一个规则附加 L,因此使其成为
RewriteRule ^/cgi-bin/java\-rmi\.cgi http://localhost/RMIServlet [P ,L]
Dav is wrong, with [P] the replacement needs to be a qualified URI, including protocol and hostname.
Is mod_proxy really active and configured correctly? Sorry, I can't help you with that, as I have not used done this yet.
Try defining RMIServlet before rewriting the URL.
Perhaps there is another rewriting going on after your rule, try appending L for last rule, so make it
RewriteRule ^/cgi-bin/java\-rmi\.cgi http://localhost/RMIServlet [P,L]
试试这个? (即省略主机部分?)
Try this instead? (Namely, omit the host portion?)