如何在nginx上重写timthumb图像?

时间:2015-04-24 16:58:01

标签: php .htaccess nginx rewrite

我的原始图像如下:

site.com/content/year/month/imagename.jpg

我使用timthumb生成缩略图,所以新链接如下:

site.com/content/timthumb.php?src=site.com/content/year/month/imagename.jpg&w=A&h=B&zc=1

我想将timthumb图片网址重写为:

site.com/img/year/month/imagename.jpg

请帮助我,非常感谢你!

- 我尝试了很多方法,但没有工作。以下是一些:

location / {
rewrite ^/img/([0-9]+)/([0-9]+)/(.*).(jpg|jpeg|png|gif) /content/timthumb.php?src=site.com/content/$1/$2/$3.$4&h=150&w=150&zc=1 break;
}

location / {
rewrite ^/img/([0-9]+)/([0-9]+)/(.*).(jpg|jpeg|png|gif) /content/timthumb.php?src=site.com/content/$1/$2/$3.$4&h=150&w=150&zc=1 last;
}

1 个答案:

答案 0 :(得分:0)

不幸的是,我没有nginx,但经过一些研究后,这可能适合你:

Sub equity()

    Dim Nav_date As Date
    Dim equity As Integer
    Dim lRow As Long
    Dim i As Long

    lRow = Sheets("Start page").Cells(Rows.Count, 1).End(xlUp).Row

    For i = 4 To lRow 'Begin in Row 4 of the "Start page" sheet
        Nav_date = Sheets("Start page").Range("A" & i).Value

        'Tell code to continue even if error occurs
        On Error Resume Next

        equity = Application.WorksheetFunction.VLookup(Nav_date, _
         Worksheets("Fund Trend").Range("A11:C12"), 3, False)

        'Check the results of the VLOOKUP, an error number of 0 means no error
        If Err.Number = 0 Then
            'Here I use i+3 because the data started in row 7 and I assume
            'it will always be offset by 3 from the "Start Page"
            Sheets("Acurred Expenses").Range("C" & i + 3).Value = equity
        End If

        'Return to normal error handling
        On Error GoTo 0

    Next i

End Sub

我只删除了主要斜线(通常在Apache中也是如此)。

更新:使用this generator来解决此问题。请试一试。

location / {
    rewrite ^img/([0-9]+)/([0-9]+)/(.*)\.(jpg|jpeg|png|gif) content/timthumb.php?src=site.com/content/$1/$2/$3.$4&h=150&w=150&zc=1 last;
}