为 Apache 2.2 和 JBoss 4.2.3 配置 mod_rewrite 和 mod_jk

发布于 2024-08-25 01:16:18 字数 1701 浏览 8 评论 0原文

我的问题如下:我的 JBoss 4.2.3 应用程序服务器与 AJP 1.3 连接器在 Windows 下的一台主机上运行(我的测试环境为 192.168.1.2),Apache 2.2.14 在另一台 FreeBSD 机器(192.168.1.10)上运行。 Apache 充当所有请求的“前门”,并通过 mod_jk 将它们发送到 JBoss。一切都工作正常,直到我必须做一些 SEO 优化。这些优化包括 SEF url,因此我决定使用 Apache 的 mod_rewrite 来更改请求,然后再将请求发送到 JBoss。基本上,我需要实现 2 条规则:

这是我的测试虚拟主机的 Apache 配置:

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/usr/local/www/dummy"
ServerName 192.168.1.10

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteRule /directory/(.*) /$1 [R=permanent,L]
    RewriteRule ^/([^/]+)/([0-9]+)/?$   /$1/view.htm?id=$2

</IfModule>

JkMount     /*      jsp-hostname

ErrorLog "/var/log/dummy-host.example.com-error_log"
CustomLog "/var/log/dummy-host.example.com-access_log" common
</VirtualHost>

问题是第二个重写规则不起作用。请求不变地传递到 JBoss,因此我收到 Tomcat 404 错误。但是,如果我将重定向标志添加到第二条规则中,就像

RewriteRule ^/([^/]+)/([0-9]+)/?$   /$1/view.htm?id=$2 [R,L]

它的魅力一样。但重定向不是我在这里需要的:)。我怀疑问题在于请求被转发到另一个主机(192.168.1.2),但我真的不知道如何使其工作。任何帮助将不胜感激:)

My problem is as follows: I have JBoss 4.2.3 application server with AJP 1.3 connector running on one host under Windows (192.168.1.2 for my test environment) and Apache 2.2.14 running on another FreeBSD box (192.168.1.10). Apache acts as a "front gate" for all requests and sends them to JBoss via mod_jk. Everything was working fine until I had to do some SEO optimizations. These optimizations include SEF urls, so i decided to use mod_rewrite for Apache to alter requests before they are sent to JBoss. Basically, I nedd to implement 2 rules:

Here is my Apache config for test virtual host:

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/usr/local/www/dummy"
ServerName 192.168.1.10

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteRule /directory/(.*) /$1 [R=permanent,L]
    RewriteRule ^/([^/]+)/([0-9]+)/?$   /$1/view.htm?id=$2

</IfModule>

JkMount     /*      jsp-hostname

ErrorLog "/var/log/dummy-host.example.com-error_log"
CustomLog "/var/log/dummy-host.example.com-access_log" common
</VirtualHost>

The problem is that second rewrite rule doesn't work. Requests slip through to JBoss unchanged, so I get Tomcat 404 error. But if I add redirect flag to the second rule like

RewriteRule ^/([^/]+)/([0-9]+)/?$   /$1/view.htm?id=$2 [R,L]

it works like a charm. But redirect is not what I need here :) . I suspect that the problem is that requests are forwarded to the another host (192.168.1.2), but I really don't have any idea on how to make it work. Any help would be appreciated :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

殤城〤 2024-09-01 01:16:18

您的第二个重写规则不起作用的原因是您使用了“?”在您的 URI 定义中,并且 URI 定义从不包含分隔符“?”。
所以只需使用没有它的重写规则即可。例如。

RewriteRule ^/([^/]+)/([0-9]+)/$   /$1/view.htm?id=$2 [R,L]

The reason your second rewrite rule doesn't work is that you use the '?' in your URI definition and the URI definition never contains the separator '?'.
So simply use the rewrite rules without it. eg.

RewriteRule ^/([^/]+)/([0-9]+)/$   /$1/view.htm?id=$2 [R,L]
多彩岁月 2024-09-01 01:16:18

简单地说,这是行不通的,因为第一个 RewriteRule 末尾有 [L],这意味着它是要处理的最后一个规则。

Simply, doesn't works because the first RewriteRule has the [L] at the end, which means is the last rule to process.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文