IIS7配置 web.config 实现 Discuz! X3 的伪静态
中午了,困的不行,一边打瞌睡一边配置Discuz! X3。。。
本地环境是 windows7 + IIS7 + PHP,配置伪静态也方便。IIS7及以上版本都集成了rewrite模块,不用像IIS6那样,还需要先加载Rewrite组件,IIS7下直接在根目录新建名为 web.config 的文件,默认内容如下:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite>……</rewrite> </system.webServer> </configuration>
在 Discuz! X3 后台的 “URL 静态化” 设置页面可以找到Rewrite规则,将IIS7的规则复制粘贴到上述代码的 “<rewrite>……</rewrite>” 部分即可,完整如下:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="portal_topic"> <match url="^(.*/)*topic-(.+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/portal.php\?mod=topic&topic={R:2}&{R:3}" /> </rule> <rule name="portal_article"> <match url="^(.*/)*article-([0-9]+)-([0-9]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/portal.php\?mod=view&aid={R:2}&page={R:3}&{R:4}" /> </rule> <rule name="forum_forumdisplay"> <match url="^(.*/)*forum-(\w+)-([0-9]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/forum.php\?mod=forumdisplay&fid={R:2}&page={R:3}&{R:4}" /> </rule> <rule name="forum_viewthread"> <match url="^(.*/)*thread-([0-9]+)-([0-9]+)-([0-9]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/forum.php\?mod=viewthread&tid={R:2}&extra=page%3D{R:4}&page={R:3}&{R:5}" /> </rule> <rule name="group_group"> <match url="^(.*/)*group-([0-9]+)-([0-9]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/forum.php\?mod=group&fid={R:2}&page={R:3}&{R:4}" /> </rule> <rule name="home_space"> <match url="^(.*/)*space-(username|uid)-(.+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/home.php\?mod=space&{R:2}={R:3}&{R:4}" /> </rule> <rule name="home_blog"> <match url="^(.*/)*blog-([0-9]+)-([0-9]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/home.php\?mod=space&uid={R:2}&do=blog&id={R:3}&{R:4}" /> </rule> <rule name="forum_archiver"> <match url="^(.*/)*(fid|tid)-([0-9]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/index.php\?action={R:2}&value={R:3}&{R:4}" /> </rule> <rule name="plugin"> <match url="^(.*/)*([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+).html\?*(.*)$" /> <action type="Rewrite" url="{R:1}/plugin.php\?id={R:2}:{R:3}&{R:4}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
到此吧,困意来袭,扛不住啊!