首页 - 开发工具
 收藏

伪静态转换

有时候需要转换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 错误页

推荐工具:

工具标签:

转换开发