IIS7.5 去除 index.php web.config配置文件


論壇里有很多關於去掉index.php的教程和代碼,但是悲劇的是都是自己能配置服務器,
並且服務器要么是 Apache,就是IIS 6- 。。。
沒有IIS7.5下是如何配置的。

我想大家應該有很多都是用的服務商提供的空間,有些文件是沒法修改的。
有一次在群里看到一個人吵着服務商垃圾,不讓他修改httpd.conf文件,
說什么你讓我改我就能偽靜態了...還說服務器垃圾,不支持URL Rwrite。

其實IIS7.5是支持的,並且可配置程度及靈活性是相當高的,
只要web.config的規則配置你懂得,其實你是可以完全無視服務商的,這個你懂得...
什么404,500etc. 過濾文件,限制訪問之類的都不算個事。

從這個角度來看,很多人由於對Web.config的不了解,以及對所看到的教程的盲目崇拜,才會鬧出上面那樣的尷尬。

不說了,直接上代碼:
web.config

XML復制代碼
 
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <system.webServer>
   <directoryBrowse enabled="false" />
   <rewrite>
      <rules>
      <rule name="OrgPage" stopProcessing="true"
       <match url="^(.*)$" />
       <conditions logicalGrouping="MatchAll"
          <add input="{HTTP_HOST}" pattern="^(.*)$" /> 
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
       </conditions
         <action type="Rewrite" url="index.php/{R:1}" /> 
</rule>
</rules>
    </rewrite>
    <defaultDocument>
            <files>
                <clear />
                <add value="index.asp" />
                <add value="index.aspx" />
                <add value="index.php" />
                <add value="index.html" />
                <add value="Default.htm" />
                <add value="Default.asp" />
                <add value="index.htm" />
                <add value="Default.aspx" />
                <add value="index.shtml" />
            </files>
        </defaultDocument>
        <httpErrors>
            <error statusCode="500" subStatusCode="1" prefixLanguageFilePath=""path="www.QFisH.net" 
responseMode="ExecuteURL" />
            <error statusCode="404" subStatusCode="1" prefixLanguageFilePath="" path="qfish.me"responseMode="Redirect" />
        </httpErrors>
    </system.webServer>
</configuration>
 
復制代碼

如果只是需要去掉index.php, 那直接把下面這段代碼加到 <system.webServer> </system.webServer>中間就可以了。

XML復制代碼
 
<rewrite>
<rules
<rule name="OrgPage" stopProcessing="true"
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll"
<add input="{HTTP_HOST}" pattern="^(.*)$" /> 
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
</conditions>
<action type="Rewrite" url="index.php/{R:1}" /> 
</rule>
</rules>
</rewrite>
 
 
復制代碼




需要注意的是還要修改 設置Codeigniter的config.php文件,該文件默認在application/config目錄下。
這個文件中的下列內容:

PHP復制代碼
 
// $config['index_page'] = "index.php"; 把其中的 "index.php" 改成 "" ,如下:
$config['index_page'"";
 
復制代碼



希望能幫到一些想在IIS7.5下去掉“index.php”的同鞋...跟詳細可以看:
IIS7.5的偽靜態URL Rewrite規則(Ci,codeigniter,eMlog,Discuz…)http://qfish.me/2011/05/iis7-5-url-rewrite.htmll


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM