discuz! x2子目錄偽靜態(tài)的實(shí)現(xiàn)方法

字號(hào):


    前幾天幫人實(shí)現(xiàn)discuz x2的子目錄偽靜態(tài),以前沒做過,就去查了下百度和discuz論壇,發(fā)現(xiàn)好多人都在找這樣的偽靜態(tài)方法,可是都沒真正能解決的方法。
    discuz x2現(xiàn)在用的人還是比較多的,我不知道有多少人用的是iis7的,用apache的就好辦一些,因?yàn)?hacess是可以設(shè)置子目錄的偽靜態(tài)規(guī)則的,但是 在iis7下,webconfig究竟怎么放才能實(shí)現(xiàn)子目錄偽靜態(tài)沒有試過,我百度的時(shí)候還有人說iis7是discuz x2的非主流環(huán)境。
    下面我就說一下在iis7下如何實(shí)現(xiàn)discuz x2的子目錄偽靜態(tài)。
    首先說明一下,在iis7下我們自己測(cè)試的時(shí)候之所以不能實(shí)現(xiàn),大部分是因?yàn)槲覀儼褌戊o態(tài)的文件放在子目錄了,造成主目錄的規(guī)則跟子目錄相互沖突。
    還有一些是在子目錄消除了主目錄的偽靜態(tài)繼承,但是依舊打不開。
    我通過多次測(cè)試發(fā)現(xiàn),iis7下的子目錄偽靜態(tài),規(guī)則要放在主目錄,而且規(guī)則的寫法不能跟主目錄的規(guī)則沖突。我這里就不說那么多理論了。直接發(fā)規(guī)則:
    <?xml version=1.0 encoding=utf-8?>
    <configuration>
    <system.webserver>
    <rewrite>
    <rules>
    <rule name=www 301redirect stopprocessing=true> // 301跳轉(zhuǎn)規(guī)則
    <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> // 論壇規(guī)則開始
    <match url=^(.*)/topic-(.+).html?*(.*)$ />
    <action type=rewrite url={r:1}/portal.php?mod=topic&amp;topic={r:2}&amp;{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&amp;aid={r:2}&amp;page={r:3}&amp;{r:4} />
    </rule>
    <rule name=forum_forumdisplay>
    <match url=^(.*)/forum-(w+)-([0-9]+).html?*(.*)$ />
    <action type=rewrite url={r:1}/forum.php?mod=forumdisplay&amp;fid={r:2}&amp;page={r:3}&amp;{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&amp;tid={r:2}&amp;extra=page%3d{r:4}&amp;page={r:3}&amp;{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&amp;fid={r:2}&amp;page={r:3}&amp;{r:4} />
    </rule>
    <rule name=home_space>
    <match url=^(.*)/space-(username|uid)-(.+).html?*(.*)$ />
    <action type=rewrite url={r:1}/home.php?mod=space&amp;{r:2}={r:3}&amp;{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&amp;uid={r:2}&amp;do=blog&amp;id={r:3}&amp;{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}&amp;value={r:3}&amp;{r:4} />
    </rule> //論壇規(guī)則結(jié)束
    <rule name=wordpress patternsyntax=wildcard> // wp偽靜態(tài)規(guī)則開始
    <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>
    基本上這個(gè)規(guī)則的子目錄已經(jīng)確定是bbs了,實(shí)在不會(huì)的朋友直接抄襲吧。