2013-06-12 80 views
0

我正在構建一個LAMP應用程序www.testing.com,我有一個圖像url www.testing.com/image/folderA/a.jpgphp htacess重定向404錯誤頁面

我希望在.htacess中有一個重寫規則,如果用戶導航到/ image/foldera中不存在的圖像,他將被重定向到另一個圖像,其URL爲www.testing.com/image/folderB/b.jpg

這是我的代碼。

RewriteRule ^image/folderA/(.*\.(jpg|gif|png))$ http://%{SERVER_NAME}/image/folderB/b.jpg [R=404,L] 

然而,這是不工作爲www.testing.com/image/folderA/a.jpg,這是應該返回圖像,給出了一個404任何想法,爲什麼?

在此先感謝。

回答

0

使用時您需要記住以下的R標誌:

However, if a status code is outside the redirect range (300-399) then the substitution string is dropped entirely, and rewriting is stopped as if the L were used.

http://httpd.apache.org/docs/trunk/rewrite/flags.html#flag_r

這意味着你的重寫規則被丟棄substition串並重定向到指定的文件的所有請求到內置的404頁面。