2011-04-08 24 views
1

example.com/thumb/AWg7X9Ko5hA_default.png某些mod rewrited圖像未加載。爲什麼?

例如,它的工作....

example.com/thumb/m0bt_9Qiznc_default.png

不是..爲什麼不呢?

當我訪問

example.com/thumb/media.php?id=m0bt_9Qiznc &類型=默認

它的工作原理。

這是我使用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"); } 
+0

這是什麼代碼? – m3tsys 2011-04-08 17:47:46

回答

1

你的重寫規則僅允許部分以下劃線分隔:

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

但是你的網址有

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

所以,你可能想你的第一個[^_]*變成只是.*更廣泛的匹配。或使用:

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

謝謝。我已經使用了'RewriteRule^thumb /([^ /] +)_([^ _] *)\。png $'現在圖片加載正常。我可以有任何更多的問題使用此代碼? – m3tsys 2011-04-08 17:29:18

+0

很酷。它不會使用'([^ /] +)',它也可以與'(\ w +)'一起使用,因爲它匹配字母,數字和下劃線。 – mario 2011-04-08 17:32:06

1

這是下劃線。

正則表達式只允許一個下劃線,但第二個文件名有兩個下劃線。

+0

非常感謝。 – m3tsys 2011-04-08 17:28:06

相關問題