前幾天幫人實現 Discuz X2 的子目錄偽靜態,以前沒做過,就去查了下百度和 Discuz 論壇,發現好多人都在找這樣的偽靜態方法,可是都沒真正能解決的方法。
Discuz X2 現在用的人還是比較多的,我不知道有多少人用的是 IIS7 的,用 Apache 的就好辦一些,因為.hacess 是可以設置子目錄的偽靜態規則的,但是 在 IIS7 下,webconfig 究竟怎麼放才能實現子目錄偽靜態沒有試過,我百度的時候還有人説 IIS7 是 Discuz X2 的非主流環境。
下面我就説一下在 IIS7 下如何實現 Discuz X2 的子目錄偽靜態。
首先説明一下,在 IIS7 下我們自己測試的時候之所以不能實現,大部分是因為我們把偽靜態的文件放在子目錄了,造成主目錄的規則跟子目錄相互衝突。
還有一些是在子目錄消除了主目錄的偽靜態繼承,但是依舊打不開。
我通過多次測試發現,IIS7 下的子目錄偽靜態,規則要放在主目錄,而且規則的寫法不能跟主目錄的規則衝突。我這裏就不説那麼多理論了。直接發規則:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WWW 301Redirect" stopProcessing="true"> // 301 跳轉規則
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain.comg$" />
</conditions>
<action type="Redirect" url="http://www.domain.com/R:0" redirectType="Permanent" />
</rule><rule name="portal_topic"> // 論壇規則開始
<match url="http://(.*)/topic-(.+).html?*(.*)$" />
<action type="Rewrite" url="" />
</rule>
<rule name="portal_article">
<match url="http://(.*)/article-(%5B0-9%5D+)-(%5B0-9%5D+).html?*(.*)$" />
<action type="Rewrite" url="" />
</rule>
<rule name="forum_forumdisplay">
<match url="http://(.*)/forum-(w+)-(%5B0-9%5D+).html?*(.*)$" />
<action type="Rewrite" url="" />
</rule>
<rule name="forum_viewthread">
<match url="http://(.*)/thread-(%5B0-9%5D+)-(%5B0-9%5D+)-(%5B0-9%5D+).html?*(.*)$" />
<action type="Rewrite" url="" />
</rule>
<rule name="group_group">
<match url="http://(.*)/group-(%5B0-9%5D+)-(%5B0-9%5D+).html?*(.*)$" />
<action type="Rewrite" url="" />
</rule>
<rule name="home_space">
<match url="http://(.*)/space-(username|uid)-(.+).html?*(.*)$" />
<action type="Rewrite" url="" />
</rule>
<rule name="home_blog">
<match url="http://(.*)/blog-(%5B0-9%5D+)-(%5B0-9%5D+).html?*(.*)$" />
<action type="Rewrite" url="" />
</rule>
<rule name="forum_archiver">
<match url="http://(.*)/(fid|tid)-(%5B0-9%5D+).html?*(.*)$" />
<action type="Rewrite" url="" />
</rule> //論壇規則結束
<rule name="WordPress" patternSyntax="Wildcard"> // WordPress 偽靜態規則開始
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/bbs1" negate="true" /></conditions>
<action type="Rewrite" url="index.php" />
</rule></rules>
</rewrite>
</system.webServer>
</configuration>
基本上這個規則的子目錄已經確定是 bbs 了,實在不會的朋友直接抄吧。