• <kbd id="sesu6"><pre id="sesu6"></pre></kbd>
    
    
    首頁 - 開發(fā)工具
     收藏

    偽靜態(tài)轉(zhuǎn)換

    有時候需要轉(zhuǎn)換IIS、Apache、Nginx、Caddy2時候,很長一段偽靜態(tài)需要重新去寫。這個時候就可以用到此工具快速轉(zhuǎn)換。

    <?xml version="1.0" encoding="UTF-8"?>
                    <configuration>
        <system.webServer>
    
            <rewrite>
                <outboundRules>
                    <preConditions>
                        <preCondition name="ResponseIsHtml1">
                            <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html"/>
                        </preCondition>
                    </preConditions>
                </outboundRules>
                <rules>
                    <clear/>
                    <rule name="thinkphp">
                        <match url="^(?!css)(.*).html$"/>
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false"/>
                        <action type="Rewrite" url="/index.php?s={R:1}"/>
                    </rule>
                    <rule name="thinkphp">
                        <match url="^(?!Public)(.*).html$"/>
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false"/>
                        <action type="Rewrite" url="/index.php?s={R:1}"/>
                    </rule>
                </rules>
            </rewrite>
            <httpErrors>
                <remove statusCode="404" subStatusCode="-1"/>
                <error statusCode="404" prefixLanguageFilePath="" path="/error/404.php" responseMode="ExecuteURL"/>
            </httpErrors>
        </system.webServer>
    </configuration>
                

    生成結(jié)果

    
            
    last,重寫后的規(guī)則,會繼續(xù)用重寫后的值去匹配下面的location。
    break,重寫后的規(guī)則,不會去匹配下面的location。使用新的規(guī)則,直接發(fā)起一次http請求了。
    錯誤頁指定conf/nginx.conf設(shè)置:error_page 404 500   = /error.html 或 error_page 404 = http://域名;
    
    rewrite '(?!css)(.*).html' /index.php?s=$1 last;
    rewrite '(?!Public)(.*).html' /index.php?s=$1 last;
                
    1) R[=code](force redirect) 強制外部重定向 
    強制在替代字符串加上http://thishost[:thisport]/前綴重定向到外部的URL.如果code不指定,將用缺省的302 HTTP狀態(tài)碼。 
    2) F(force URL to be forbidden)禁用URL,返回403HTTP狀態(tài)碼。 
    3) G(force URL to be gone) 強制URL為GONE,返回410HTTP狀態(tài)碼。 
    4) P(force proxy) 強制使用代理轉(zhuǎn)發(fā)。 
    5) L(last rule) 表明當前規(guī)則是最后一條規(guī)則,停止分析以后規(guī)則的重寫。 
    6) N(next round) 重新從第一條規(guī)則開始運行重寫過程。 
    7) C(chained with next rule) 與下一條規(guī)則關(guān)聯(lián)
    8) QSA 繼續(xù)傳遞GET參數(shù)
    RewriteRule規(guī)則表達式的說明:
    . 匹配任何單字符 
    [chars] 匹配字符串:chars 
    [^chars] 不匹配字符串:chars 
    text1|text2 可選擇的字符串:text1或text2 
    ? 匹配0到1個字符 
    * 匹配0到多個字符 
    + 匹配1到多個字符 
    ^ 字符串開始標志 
    $ 字符串結(jié)束標志 
    n 轉(zhuǎn)義符標志
    
    RewriteEngine On
    RewriteRule (?!css)(.*).html$ /index.php?s=$1 [L]
    RewriteRule (?!Public)(.*).html$ /index.php?s=$1 [L]
    ErrorDocument 404 /error/404.php
                
           <?xml version="1.0" encoding="UTF-8"?>
                <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <clear/>
                    <rule name="thinkphp">
                        <match url="^(?!Public)(.*).html$"/>
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false"/>
                        <action type="Rewrite" url="/index.php?s={R:1}"/>
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    
            

    工具說明:

    輸入IIS、nginx、Apache、caddy2偽靜態(tài)選擇轉(zhuǎn)換對象,即可轉(zhuǎn)換成對應的偽靜態(tài)規(guī)則。

    2020-7-16 新增nginx轉(zhuǎn)caddy2

    2018-9-29 新增iis轉(zhuǎn)Apache 錯誤頁

    推薦工具:

    工具標簽:

    轉(zhuǎn)換開發(fā)