Windows主机下规则文件web.config

2026年06月19日 作者头像 作者头像 admin 编辑

请输入图片描述

Windows主机下规则文件web.config(可手工创建web.config文件到站点根目录)添加以下规则:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <!-- 规则1: 15.cx HTTP -> HTTPS 并强制跳转到 index.php -->
                <rule name="bbs_https" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" ></match>
                    <conditions logicalGrouping="MatchAll">                       
                        <add input="{HTTP_FROM_HTTPS}" pattern="^on$" negate="true" ></add>
                        <add input="{HTTP_HOST}" pattern="15\.cx$" />  
                    </conditions>
                    <action type="Redirect" url="https://15.cx/index.php" redirectType="Permanent" ></action>
                </rule>

                <!-- 规则2: 15.cx 如果已经是 HTTPS,但访问根路径,确保指向 index.php (可选,防止根目录缓存) -->
                <rule name="bbs_root_to_index" stopProcessing="true">
                    <match url="^$" ignoreCase="false" ></match>
                    <conditions logicalGrouping="MatchAll">                       
                        <add input="{HTTP_HOST}" pattern="15\.cx$" />  
                    </conditions>
                    <action type="Redirect" url="https://15.cx/index.php" redirectType="Permanent" ></action>
                </rule>
                
                <!-- 规则3: pay.18.cx HTTP -> HTTPS -->
                <rule name="pay_https" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" ></match>
                    <conditions logicalGrouping="MatchAll">                       
                        <add input="{HTTP_FROM_HTTPS}" pattern="^on$" negate="true" ></add>
                        <add input="{HTTP_HOST}" pattern="pay\.18\.cx$" />  
                    </conditions>
                    <action type="Redirect" url="https://18.cx/zhifu/{R:1}" redirectType="Permanent" ></action>
                </rule>
                
                <!-- 规则4: 其他所有 HTTP 请求升级 HTTPS -->
                <rule name="all_https" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" ></match>
                    <conditions logicalGrouping="MatchAll">                       
                        <add input="{HTTP_FROM_HTTPS}" pattern="^on$" negate="true" ></add>  
                    </conditions>
                    <action type="Redirect" url="https://18.cx/{R:1}" redirectType="Permanent" ></action>
                </rule>
                
                <!-- 规则5: Typecho 伪静态路由 -->
                <rule name="Typecho-bbs" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer> 
</configuration>

内容声明: 本文内容版权归原作者所有。根据《用户协议》,本文 公开内容 适用 CC BY-NC-SA 4.0 协议。

允许非商业性使用,转发或引用时请务必 注明作者及原文链接! 如涉侵权或违反《 用户协议 》,请立即联系我们以便及时处理。

*注:基于本文再创作的衍生作品须采用 相同或兼容 的协议发布; 平台享有永久、不可撤销的非独家使用权。

猜你喜欢