【问题标题】:URL Rewrite with Tomcat not working使用 Tomcat 重写 URL 不起作用
【发布时间】:2015-03-28 07:31:00
【问题描述】:

我在tomcat(通过mod_jk)前使用apache 2.2.9,它有一个ROOT文件夹和webapp下的一些.html文件。

我默认配置 URL 重写:

<VirtualHost *:80>
    <IfModule mod_rewrite.c>
    RewriteLog /var/log/apache2/rewrite.log
    RewriteLogLevel 3
    </IfModule>
    ServerAdmin webmaster@localhost
    ServerName www.megamadz.com
    ServerAlias megamadz.com
    DocumentRoot /usr/tomcat/webapps
    JKMount /* ajp13_worker

    ...
    AllowOverride All

我将 .htaccess 放在 webapps 和 ROOT 下,但是 rewrite.log 的输出为 0,无论我在浏览器中输入什么,http://mydomain/about-us 它都说 ... 不可用,它从不指向 http://mydomain/about-us.html

这是我的 .htaccess 文件:

RewriteEngine On    # Turn on the rewriting engine
RewriteRule    ^about-us$              about-us.html    [NC,L]

【问题讨论】:

  • 你可以试试RewriteRule ^/about-us$ about-us.html [NC,L]
  • Same, 404, 0 rewrite.log, 这里是.htacess: RewriteEngine On # 开启重写引擎 RewriteRule ^/about-us$ about-us.html [NC,L] RewriteRule ^ /advertising$ ads/advertising.html [NC,L] RewriteRule ^marketing$ marketing/marketing.html [NC,L] RewriteRule ^advertising-platform?$advertising-platform/advertising-platform.html [NC,L]跨度>
  • rewrite.log 里有没有录入?
  • 不,0字节,不知道怎么回事。
  • 你能尝试在你的 http.conf 中添加命令吗(不是在 .htaccess 中)?

标签: apache tomcat configuration


【解决方案1】:

你正在尝试的东西永远不会奏效。 JKMount /* ajp13_worker 表示所有请求都转发到 Tomcat,而不是由 Apache 处理。因为 Apache 不处理请求,所以它也不会处理 .htaccess 文件。

按照现在的情况,您应该在 Tomcat 中进行重写。如果这不是您想要做的,您应该将您的重写规则移动到虚拟主机中,以便处理它们。

但是看起来您正在尝试重写静态文件,但是您有一个设置,基本上所有事情都由 Tomcat 处理。也许您实际上需要像 JKMount /someApp 这样的东西,创建一个场景,其中 Tomcat 只处理 Web 应用程序的请求,而 Apache 提供静态文件。

【讨论】:

  • 当我在路径之间用破折号(-)重写时: ,/mobile-ad-with-video/... 浏览器将其取出。如何防止它取出破折号?
猜你喜欢
  • 1970-01-01
  • 2012-01-25
  • 1970-01-01
  • 2016-12-18
  • 2023-03-24
  • 1970-01-01
相关资源
最近更新 更多