首頁 - 開發工具
 收藏

偽靜態轉換

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

<?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>
            

生成結果


        
last,重寫后的規則,會繼續用重寫后的值去匹配下面的location。
break,重寫后的規則,不會去匹配下面的location。使用新的規則,直接發起一次http請求了。
錯誤頁指定conf/nginx.conf設置: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狀態碼。 
2) F(force URL to be forbidden)禁用URL,返回403HTTP狀態碼。 
3) G(force URL to be gone) 強制URL為GONE,返回410HTTP狀態碼。 
4) P(force proxy) 強制使用代理轉發。 
5) L(last rule) 表明當前規則是最后一條規則,停止分析以后規則的重寫。 
6) N(next round) 重新從第一條規則開始運行重寫過程。 
7) C(chained with next rule) 與下一條規則關聯
8) QSA 繼續傳遞GET參數
RewriteRule規則表達式的說明:
. 匹配任何單字符 
[chars] 匹配字符串:chars 
[^chars] 不匹配字符串:chars 
text1|text2 可選擇的字符串:text1或text2 
? 匹配0到1個字符 
* 匹配0到多個字符 
+ 匹配1到多個字符 
^ 字符串開始標志 
$ 字符串結束標志 
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偽靜態選擇轉換對象,即可轉換成對應的偽靜態規則。

2020-7-16 新增nginx轉caddy2

2018-9-29 新增iis轉Apache 錯誤頁

推薦工具:

工具標簽:

轉換開發