2017-08-09 174 views
0

我在.htaccess以下重寫:htaccess的重寫條件nginx的配置 - 多個條件&重寫

#exception for shorthand phpthumb links eg /userfiles/myimage.jpg?w=300 
RewriteCond %{REQUEST_URI} \.(jpg|jpeg|png|gif|bmp|JPG|)$ 
RewriteCond %{QUERY_STRING} ^(.+)$ 
RewriteRule ^(.*)$ application/third_party/phpThumb/phpThumb.php?src=../../../$1&%1 [NE,L] 

它檢查請求是針對指定的(圖像)文件中的一個,並且具有一定的查詢字符串參數。在這種情況下,它應該重寫爲自動縮略圖腳本。

我想重寫到nginx配置。到目前爲止,我有這樣的:

location \.(jpg|jpeg|png|gif|bmp|JPG)$ { 
    if($args ~ "^(.+)$"){ 
     rewrite ^/(.*)$ /application/third_party/phpThumb/phpThumb.php?src=../../../$1 last; 
    } 
} 

我是新來nginx的,並試圖粘合起來,從一些應用手冊,新的配置和該轉換器: http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

但它似乎並沒有工作。我究竟做錯了什麼?

回答

0

我已經取代了重寫下列要求:

location ~ /(images|userfiles)/ { 
    if ($args) { 
     # alternative shorthand phpthumb links eg /userfiles/myimage.jpg?w=300 
     rewrite .(jpg|jpeg|png|gif)$ /application/third_party/phpThumb/phpThumb.php?src=../../..$uri last; 
    } 
}