妙数

iis7环境下配置typecho伪静态规则记录
此规则可以实现去掉typecho链接中的index.php,可以实现中文搜索,中文标签,中文栏目等功能(网上搜索的...
扫描右侧二维码阅读全文
20
2018/09

iis7环境下配置typecho伪静态规则记录

此规则可以实现去掉typecho链接中的index.php,可以实现中文搜索,中文标签,中文栏目等功能(网上搜索的大部分会存在无法识别中文的情况)

共需配置两个文件
  1. web.config
    <rewrite>
        <rules>
            <rule name="cnUrl" stopProcessing="true">
                <match url="^(tag|category|search)/(.*)$" />
                <action type="Rewrite" url="cnurl.php" />
            </rule>
            <rule name="Typecho rewrite" 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" />
            </rule>    
        </rules>
    </rewrite>
  1. cnurl.php文件(此文件需要自己在根目录新建)
    <?php
    if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
        // IIS Mod-Rewrite
        $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
    } else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
        // IIS Isapi_Rewrite
        $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
    } else {
        // Use ORIG_PATH_INFO if there is no PATH_INFO
        (!isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO'])) && ($_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO']);
        // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
        if (isset($_SERVER['PATH_INFO'])) {
            ($_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME']) ? ($_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO']) : ($_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO']);
        }
        // Append the query string if it exists and isn't null
        (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) && ($_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']);
    }
    require("index.php");
    ?>

伪静态.png

最后修改:2018 年 10 月 23 日 03 : 43 PM
如果觉得我的文章对你有用,请随意赞赏

发表评论