重写规则:添加具有静态内容的别名,而不会被以前的规则重写

发布于 2024-12-01 02:04:36 字数 6473 浏览 2 评论 0原文

我有规则(如下),并且我们添加了一个新别名 /msn,其中包含一些静态内容,例如 html 文件 ayuda.html,它是目录索引文件和一些图像。

目前我可以看到 HTML 文件,但看不到图像。此外,根据我是否访问domain.com/msndomain.com/msn/,还会出现不同的错误。在第一种情况下,图像位置不会被重写为 domain.com/msn/image-blah-blah.jpg,但在第二种情况下会被重写。

这是虚拟目录:

<VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot "/opt/tomcat-5.5.30/webapps/portalPA"
        ServerAlias *.amarillas.tm.yellargentina.com
        CustomLog /tmp/amarillas-access_log combined
        ErrorLog /tmp/amarillas-error_log
        RewriteLog /tmp/amarillas-rewrite_log
        RewriteLogLevel 9

        JkUnMount       /images/*.gif           w1
        JkUnMount       /images/*.png           w1
        JkUnMount       /images/*.jpg           w1
        JkUnMount       /js/*.js                w1
        JkUnMount       /styles/*.css           w1

        #JkMount        /jkmanager/*            jkstatus
        JkMount         /portalPA               w1
        JkMount         /portalPA/*             w1
        JkUnMount       /msn/*                  w1

        CookieName PaginasAmarillas
        CookieExpires "2 years"
        CookieDomain ".tm.yellargentina.com"
        RewriteEngine on
        RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
        RewriteRule .* - [F]
        Options +FollowSymlinks

        RewriteRule ^/(msn|msn/) /msn/ayuda.html [PT]
        RewriteRule ^/msn/ayuda.html$ /msn/ [R,L]
        RewriteRule ^/msn/(?!ayuda.html)(.*) /msn/$1 [R,L]

        RewriteRule ^/$ /portalPA/index.action   [PT]
        RewriteRule ^/portalPA/index.action / [R]
        RewriteRule ^/(?!portalPA/)(.*) /portalPA/$1 [PT]
</VirtualHost>

当我尝试访问 domain.com/msn/ 时的日志

10.248.19.52 - - [23/Aug/2011:16:54:36 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc8338/initial] (2) init rewrite engine with requested uri /msn/yello-apps-mesenger.jpg
10.248.19.52 - - [23/Aug/2011:16:54:36 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc8338/initial] (3) applying pattern '.*' to uri '/msn/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:54:36 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc8338/initial] (4) RewriteCond: input='GET' pattern='^(TRACE|TRACK)' => not-matched
10.248.19.52 - - [23/Aug/2011:16:54:36 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc8338/initial] (3) applying pattern '^/(msn|msn/)' to uri '/msn/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:54:36 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc8338/initial] (2) rewrite '/msn/yello-apps-mesenger.jpg' -> '/msn/ayuda.html'
10.248.19.52 - - [23/Aug/2011:16:54:36 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc8338/initial] (2) forcing '/msn/ayuda.html' to get passed through to next API URI-to-filename handler

当我尝试访问 domain.com/msn 时的日志

10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc02f8/initial] (2) init rewrite engine with requested uri /msn
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc02f8/initial] (3) applying pattern '.*' to uri '/msn'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc02f8/initial] (4) RewriteCond: input='GET' pattern='^(TRACE|TRACK)' => not-matched
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc02f8/initial] (3) applying pattern '^/(msn|msn/)' to uri '/msn'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc02f8/initial] (2) rewrite '/msn' -> '/msn/ayuda.html'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc02f8/initial] (2) forcing '/msn/ayuda.html' to get passed through to next API URI-to-filename handler
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (2) init rewrite engine with requested uri /yello-apps-mesenger.jpg
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '.*' to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (4) RewriteCond: input='GET' pattern='^(TRACE|TRACK)' => not-matched
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '^/(msn|msn/)' to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '^/msn/ayuda.html$' to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '^/msn/(?!ayuda.html)(.*)' to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '^/$' to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '^/portalPA/index.action' to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '^/(?!portalPA/)(.*)' to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (2) rewrite '/yello-apps-mesenger.jpg' -> '/portalPA/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (2) forcing '/portalPA/yello-apps-mesenger.jpg' to get passed through to next API URI-to-filename handler

I have the rules (below) and we have added a new alias /msn which has some static content, like an html file ayuda.html which is the directory index file and some images.

Currently I can see the HTML file, but not the image. Also there are different errors depending if I go to domain.com/msn or domain.com/msn/. On the first case the image location is not being rewritten to domain.com/msn/image-blah-blah.jpg, but it does on the second case.

This is the Virtual Directory:

<VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot "/opt/tomcat-5.5.30/webapps/portalPA"
        ServerAlias *.amarillas.tm.yellargentina.com
        CustomLog /tmp/amarillas-access_log combined
        ErrorLog /tmp/amarillas-error_log
        RewriteLog /tmp/amarillas-rewrite_log
        RewriteLogLevel 9

        JkUnMount       /images/*.gif           w1
        JkUnMount       /images/*.png           w1
        JkUnMount       /images/*.jpg           w1
        JkUnMount       /js/*.js                w1
        JkUnMount       /styles/*.css           w1

        #JkMount        /jkmanager/*            jkstatus
        JkMount         /portalPA               w1
        JkMount         /portalPA/*             w1
        JkUnMount       /msn/*                  w1

        CookieName PaginasAmarillas
        CookieExpires "2 years"
        CookieDomain ".tm.yellargentina.com"
        RewriteEngine on
        RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
        RewriteRule .* - [F]
        Options +FollowSymlinks

        RewriteRule ^/(msn|msn/) /msn/ayuda.html [PT]
        RewriteRule ^/msn/ayuda.html$ /msn/ [R,L]
        RewriteRule ^/msn/(?!ayuda.html)(.*) /msn/$1 [R,L]

        RewriteRule ^/$ /portalPA/index.action   [PT]
        RewriteRule ^/portalPA/index.action / [R]
        RewriteRule ^/(?!portalPA/)(.*) /portalPA/$1 [PT]
</VirtualHost>

Logs for when I try to access to domain.com/msn/

10.248.19.52 - - [23/Aug/2011:16:54:36 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc8338/initial] (2) init rewrite engine with requested uri /msn/yello-apps-mesenger.jpg
10.248.19.52 - - [23/Aug/2011:16:54:36 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc8338/initial] (3) applying pattern '.*' to uri '/msn/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:54:36 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc8338/initial] (4) RewriteCond: input='GET' pattern='^(TRACE|TRACK)' => not-matched
10.248.19.52 - - [23/Aug/2011:16:54:36 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc8338/initial] (3) applying pattern '^/(msn|msn/)' to uri '/msn/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:54:36 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc8338/initial] (2) rewrite '/msn/yello-apps-mesenger.jpg' -> '/msn/ayuda.html'
10.248.19.52 - - [23/Aug/2011:16:54:36 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc8338/initial] (2) forcing '/msn/ayuda.html' to get passed through to next API URI-to-filename handler

Logs for when I try to access to domain.com/msn

10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc02f8/initial] (2) init rewrite engine with requested uri /msn
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc02f8/initial] (3) applying pattern '.*' to uri '/msn'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc02f8/initial] (4) RewriteCond: input='GET' pattern='^(TRACE|TRACK)' => not-matched
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc02f8/initial] (3) applying pattern '^/(msn|msn/)' to uri '/msn'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc02f8/initial] (2) rewrite '/msn' -> '/msn/ayuda.html'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bc02f8/initial] (2) forcing '/msn/ayuda.html' to get passed through to next API URI-to-filename handler
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (2) init rewrite engine with requested uri /yello-apps-mesenger.jpg
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '.*' to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (4) RewriteCond: input='GET' pattern='^(TRACE|TRACK)' => not-matched
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '^/(msn|msn/)' to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '^/msn/ayuda.html
 to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '^/msn/(?!ayuda.html)(.*)' to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '^/
 to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '^/portalPA/index.action' to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (3) applying pattern '^/(?!portalPA/)(.*)' to uri '/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (2) rewrite '/yello-apps-mesenger.jpg' -> '/portalPA/yello-apps-mesenger.jpg'
10.248.19.52 - - [23/Aug/2011:16:55:33 --0300] [amarillas.tm.yellargentina.com/sid#2af084b03cd0][rid#2af084bb82b8/initial] (2) forcing '/portalPA/yello-apps-mesenger.jpg' to get passed through to next API URI-to-filename handler

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

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

发布评论

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

评论(1

软糯酥胸 2024-12-08 02:04:36

根据提供的重写日志,我得出的结论是 yello-apps-mesenger.jpg 是有问题的图像。据我了解,上述图像是从 /msn 页面链接的。

我认为这完全取决于您如何编写 标签(或者您在哪里使用该图像)。我猜它是相对于当前文档声明的,如下所示:

好吧——这就是问题所在:

  • 当您请求 domain.com/msn/ 时,该图像将被请求为 domain.com/msn/yello-apps-mesenger.jpg
  • 但是当您请求domain.com/msn(没有尾部斜杠)时,图像将被请求为domain.com/yello-apps-mesenger.jpg并且^/(msn|msn/) 根本没有应用到它。

说实话,我不知道哪一个做错了——你对此不清楚(至少我无法弄清楚ATM)。

我看到有两种方法可以解决此问题:

1. 仅接受 domain.com/msn/ 而不是 domain.com/msn (或其他方式)并在制定规则时牢记这一点。

2. 修复图像 URL - 使其相对于网站根目录,例如: (注意前导斜杠).. 或者可能 /msn/ 是一部分的图片 URL)——您应该更好地了解什么对您有好处。

Based on rewrite logs provided I came to conclusion that yello-apps-mesenger.jpg is the problematic image in question. As I understand the aforementioned image is linked from that /msn page.

I think it is all about how you wrote your <img> tag (or where you are using that image). I guess it is declared relative to the current document like this: <img src="yello-apps-mesenger.jpg" />.

Well -- that is the problem:

  • when you requesting domain.com/msn/ that image will be requested like domain.com/msn/yello-apps-mesenger.jpg
  • but when you requesting domain.com/msn (without trailing slash), the image will be requested like domain.com/yello-apps-mesenger.jpg and ^/(msn|msn/) simply not got applied to it.

TBH I do not know which one is doing wrong -- you are not clear on this (at least I cannot figure it out ATM).

I see 2 approaches to fix the issue:

1. Only accept domain.com/msn/ and not domain.com/msn (or other way around) and build your rules with this in mind.

2. Fix image URLs -- make then relative to the website root, for example: <img src="/yello-apps-mesenger.jpg" /> (notice the leading slash) .. or maybe <img src="/msn/yello-apps-mesenger.jpg" /> (/msn/ is part of image URL) -- you should know better what is good for you.

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