簡體   English   中英

將IIS的web.config中的URL重寫為nginx.conf

[英]URL Rewrite in web.config of IIS to nginx.conf

nginx的新手,完全感到困惑。

如何將此URL重寫轉換為nginx?

<rewrite>   
    <rules>
        <rule name="IndexFolders" stopProcessing="true">
            <match url="(.*[^/]+)$" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" />
            </conditions>
            <action type="Rewrite" url="/_index/{R:1}.html" />
        </rule>
        <rule name="OtherFile" stopProcessing="true">
            <match url="\.\w+$" />
        </rule>
        <rule name="HtmlFile" stopProcessing="true">
            <match url="^([^.]*[^/]+)$" />
            <action type="Rewrite" url="{R:1}.html" />
        </rule>
    </rules>
</rewrite>

嘗試使用轉換器,但無法正常工作。

location / {
    if (-d $request_filename){
        set $rule_0 1;
    }
    if ($rule_0 = "1"){
        rewrite /(.*[^/]+)$ /_index/$1.html last;
    }
    location ~* /\.\w+$ {
        break;
    }
    rewrite ^/([^.]*[^/]+)$ /$1.html last;
}

這在我的測試環境中有效:

location / {
    if (-d $request_filename){
        rewrite ^/(.*[^/]+)/$ /_index/$1.html break;
    }

    location ~* /.*\.\w+$ {
        break;
    }

    rewrite ^/([^.]*[^/]+)$ /$1.html break;
}            

注意nginx 重寫指令

可選標志參數可以是以下之一:

持續

停止處理當前的ngx_http_rewrite_module指令集,並開始搜索與更改后的URI相匹配的新位置;

打破

與break指令一樣,停止處理當前的ngx_http_rewrite_module指令集;

因此,如果您不想在下一個循環中搜索重寫的URL以匹配規則,則應使用break

中斷指令:

停止處理當前的ngx_http_rewrite_module指令集。

如果在位置內指定了指令,則在該位置繼續對請求的進一步處理。

這類似於URL Rewriter行為:

規則可能已啟用StopProcessing標志。 啟用此標志時,意味着不再處理任何后續規則,並且此規則生成的URL將傳遞到IIS請求管道(如果規則匹配)。 默認情況下,此標志是關閉的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM