2015-12-08 11 views
0

我試圖用timthumb庫調整圖像的大小。
我可以通過以下網址.htaccess重寫規則與正則表達式不工作,返回404

http://localhost/study/server/resize/thumb.php?src=http://localhost/study/server/product/1/1/orig-1.jpg&w=160&h=130

直接使用它,它工作正常。

但是,當我重寫我的網址這樣

http://localhost/study/server/resize/160x130/r/product/1/1/orig-1.jpg 

,並添加

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !^/(resize) [NC] 
    RewriteRule ^resize/(.*)x(.*)/r/(.*) resize/thumb.php?src=http://localhost/study/server/$3&h=$2&w=$1&c=1 
</IfModule> 

不幸的是這條規則返回404錯誤

+0

您可以使用哪些服務器WAMP或XAMMP ...? – jay

+0

ubuntu apache2 httpd –

回答

0

使用此RewriteRule

RewriteRule ^study/server/resize/([0-9]+)x([0-9]+)/r/product/([0-9]+)/([0-9]+)/(.*)$ 
/study/server/resize/thumb.php?src=/study/server/product/$3/$4/$5&w=$1&h=$2 [L] 

組1寬度,零個或多個數字
組2高度相匹配,零個或多個數字
組3後/產品/,一個數位,則可以根據需要修改第一個數字匹配相匹配
組4第二個數字匹配之後/產品/,一個數位,則可以根據需要
組5文件名

此條件匹配修改

RewriteCond %{REQUEST_URI} !^/(resize) [NC] 

不需要