xmao’s blog

Tag: rewrite

Discuz 在IIS7下的Rewrite规则

by xmao on Mar.06, 2009, under Development, Internet, System, Windows Server

Discuz使用IIS7的Rewrite模块,与官方使用第三方的规则还是略有区别,给个简单例子,你可以举一反三..
加入到web.config中的..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
        <rewrite>
            <rules>
                <rule name="Forumdisplay Rewrite Rule" stopProcessing="true">
                    <match url="^forum-([^/]+)-([^/]+).html?$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="forumdisplay.php?fid={R:1}&amp;page={R:2}" />
                </rule>
                <rule name="Viewthread Rewrite Rule" stopProcessing="true">
                    <match url="^thread-([^/]+)-([^/]+)-([^/]+).html?$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="viewthread.php?tid={R:1}&amp;extra=page%3D{R:2}&amp;page={R:3}" />
                </rule>
            </rules>
        </rewrite>
Leave a Comment :, , more...

wordpress2.71在iis7下rewrite完美解决

by xmao on Feb.17, 2009, under Internet, Wordpress

解决中文路径问题

wordpress设定Permalink后一个最大的问题是中文不正常,主要原因是IIS解释路径是GBK编码,转给wordpress按UTF-8取值就不对了。

解决办法

打开wp-includes\classes.php文件,找到

1
2
3
4
5
6
7
if ( isset($_SERVER['PATH_INFO']) )
        $pathinfo = $_SERVER['PATH_INFO'];
else
        $pathinfo = '';
        $pathinfo_array = explode('?', $pathinfo);
        $pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
        $req_uri = $_SERVER['REQUEST_URI'];

替换为:

1
2
3
4
5
6
7
if ( isset($_SERVER['PATH_INFO']) )
        $pathinfo = mb_convert_encoding($_SERVER['PATH_INFO'], "UTF-8", "GBK");
else
        $pathinfo = '';
        $pathinfo_array = explode('?', $pathinfo);
        $pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
        $req_uri = mb_convert_encoding($_SERVER['REQUEST_URI'], "UTF-8", "GBK");

index.php模式

wordpress通过index.php实现的友好路径已经很不错了,你在Permalink Settings直接设置就行了..这个模式在IIS7下面很正常

如果你实在是一个完美主义者请继续往下

IIS7 rewrite组件模式

下载组件和相关说明参见:

Microsoft URL Rewrite Module for IIS 7.0 (x86)

Using URL Rewrite Module

如果您时间有限,请看以下简单安装

1 下载安装..这个必须的,安装完,你会看到IIS管理器中多了个URL Rewrite功能,但我们不用管它。

2 打开wordpress目录中的web.config,在system.webServer element中添加

1
2
3
4
5
6
7
8
9
10
11
12
<rewrite>
    <rules>
        <rule name="Main Rule" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php" />
        </rule>
    </rules>
</rewrite>

3 然后你就可以在Permalink Settings去掉看不顺眼的index.php了 :)

2 Comments :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...