我对 apache 还很陌生,所以任何帮助我都非常感谢!我的桌面上运行着 Apache 和 tomcat(通过 mod_jk)。我定义了所有静态文件(即 HTML)由 apache 提供,所有 jsp 都转发到 tomcat
我可以直接访问所有 jsp 和 html 文件,没有任何问题。例如:
- localhost/sb/jsp/index.html – 有效
- localhost/sb/jsp/dates.jsp-有效
我正在尝试重写所有 URL,这样就不需要经过 sb/jsp。含义:
- localhost/index.html 重写为 localhost/sb/jsp/index.html
- localhost/dates.jsp 重写为 localhost/sb/jsp/dates.jsp
很简单吧?
问题是 mod_rewrite 对 html 很有效,但对 jsp 却不行。我甚至可以在日志中看到对 jsp 文件强制执行了重写,但我仍然得到 404:
127.0.0.1 - - [31/Jul/2010:22:01:04 +0300] [localhost/sid#9154d0][rid#927ce0/initial] (2) init rewrite engine with requested uri /dates.jsp
127.0.0.1 - - [31/Jul/2010:22:01:04 +0300] [localhost/sid#9154d0][rid#927ce0/initial] (3) applying pattern '/dates.jsp' to uri '/dates.jsp'
127.0.0.1 - - [31/Jul/2010:22:01:04 +0300] [localhost/sid#9154d0][rid#927ce0/initial] (2) rewrite '/dates.jsp' -> '/sb/jsp/dates.jsp'
127.0.0.1 - - [31/Jul/2010:22:01:04 +0300] [localhost/sid#9154d0][rid#927ce0/initial] (2) local path result: /sb/jsp/dates.jsp
127.0.0.1 - - [31/Jul/2010:22:01:04 +0300] [localhost/sid#9154d0][rid#927ce0/initial] (1) go-ahead with C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/sb/jsp/dates.jsp [OK]
有人知道为什么会发生这种情况吗?下面粘贴的是我配置了所有内容的 mod_jk.conf。
########## Auto generated on Sat Jul 31 20:46:04 IDT 2010##########
<IfModule !mod_jk.c>
LoadModule jk_module "modules/mod_jk.so"
</IfModule>
<VirtualHost localhost>
ServerName localhost
# Options +FollowSymLinks
RewriteLogLevel 9
RewriteLog "C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/rewrite.log"
RewriteEngine on
RewriteRule /index.html /sb/jsp/index.html
RewriteRule /dates.jsp /sb/jsp/dates.jsp
# JkMount / ajp13
JkMount /*.jsp ajp13
DocumentRoot "C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps"
JkMount /manager ajp13
JkMount /manager/* ajp13
# JkMount /sb ajp13
# JkMount /sb/* ajp13
JkMount /docs ajp13
JkMount /docs/* ajp13
JkMount /examples ajp13
JkMount /examples/* ajp13
JkMount /host-manager ajp13
JkMount /host-manager/* ajp13
</VirtualHost>
答案1
检查 mod_rewrite 是否在 mod_jk 之前加载,以便 mod_rewrite 能够在 mod_jk 之前处理请求。