【问题标题】:some mod rewrited images are not loading. why?一些 mod 重写的图像没有加载。为什么?
【发布时间】:2011-04-08 17:02:28
【问题描述】:

example.com/thumb/AWg7X9Ko5hA_default.png

例如它正在工作....

但是

example.com/thumb/m0bt_9Qiznc_default.png

不是..为什么不呢?

当我访问时

example.com/thumb/media.php?id=m0bt_9Qiznc&type=default

它有效。

这是我使用的 htaccess 代码:

RewriteEngine on
RewriteBase /
RewriteRule ^thumb/([^_]*)_([^_]*)\.png$ /thumb/script.php?id=$1&type=$2 [L]

和script.php:

$media_type = $_REQUEST['type'];
$the_id=$_REQUEST['id'];
if ($media_type=="big") 
{
header('Content-type: image/png');
readfile("http://i4.ytimg.com/vi/$the_id/0.jpg");
}
elseif ($media_type=="default") {
header('Content-type: image/png');
readfile("http://i4.ytimg.com/vi/$the_id/default.jpg"); }

【问题讨论】:

    标签: php apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    您的 RewriteRule 只允许 两个 由下划线分隔的部分:

     RewriteRule ^thumb/([^_]*)_([^_]*)\.png$
    

    但是你的网址有三个

     example.com/thumb/m0bt_9Qiznc_default.png
                         ^     ^      ^
                         1 _   2  _   3
    

    因此,您可能希望将您的第一个 [^_]* 更改为 .* 以进行更广泛的匹配。或使用:

     RewriteRule ^thumb/([^/]+)_([^_]*)\.png$
    

    【讨论】:

    • 谢谢。我用过RewriteRule ^thumb/([^/]+)_([^_]*)\.png$,现在图像加载得很好。使用此代码我还有什么问题吗?
    • 酷。除了([^/]+),它也可以与(\w+)一起使用,因为它匹配字母、数字和下划线。
    【解决方案2】:

    是下划线。

    正则表达式只允许一个下划线,但第二个文件名中有两个下划线。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-04
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      • 1970-01-01
      • 2011-09-26
      • 1970-01-01
      • 2015-07-23
      相关资源
      最近更新 更多