0

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

目前我可以看到 HTML 文件,但看不到图像。也有不同的错误取决于我去domain.com/msndomain.com/msn/。在第一种情况下,图像位置没有被重写为domain.com/msn/image-blah-blah.jpg,但在第二种情况下确实如此。

这是虚拟目录:

<VirtualHost *:80>
        ServerAdmin administracion.linux@yellargentina.com
        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
4

1 回答 1

0

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

我认为这完全取决于您如何编写<img>标签(或您在哪里使用该图像)。我猜它是相对于当前文档声明的,如下所示<img src="yello-apps-mesenger.jpg" />

嗯——这就是问题所在:

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

TBH 我不知道哪个做错了——你不清楚这一点(至少我无法弄清楚 ATM)。

我看到了两种解决问题的方法:

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

2.修复图像 URL——然后相对于网站根目录,例如:(<img src="/yello-apps-mesenger.jpg" />注意前导斜杠).. 或者<img src="/msn/yello-apps-mesenger.jpg" />(可能/msn/是图像 URL 的一部分)——你应该更清楚什么对你有好处。

于 2011-08-24T00:07:18.563 回答