qfish 发表于 2011-5-28 14:56:26

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

本帖最后由 qfish 于 2011-5-29 13:27 编辑

论坛里有很多关于去掉index.php的教程和代码,但是悲剧的是都是自己能配置服务器,
并且服务器要么是 Apache,就是IIS 6- 。。。
没有IIS7.5下是如何配置的。

我想大家应该有很多都是用的服务商提供的空间,有些文件是没法修改的。
有一次在群里看到一个人吵着服务商垃圾,不让他修改httpd.conf文件,
说什么你让我改我就能伪静态了:L...还说服务器垃圾,不支持URL Rwrite。

其实IIS7.5是支持的,并且可配置程度及灵活性是相当高的,
只要web.config的规则配置你懂得,其实你是可以完全无视服务商的;P,这个你懂得...
什么404,500etc. 过滤文件,限制访问之类的都不算个事。

从这个角度来看,很多人由于对Web.config的不了解,以及对所看到的教程的盲目崇拜,才会闹出上面那样的尴尬。

不说了,直接上代码:
web.config

<?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>中间就可以了。


<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目录下。
这个文件中的下列内容:

// $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

eprgdip 发表于 2013-9-18 14:30:29

如果我的网站在CI文件夹下面怎么写呢

MANGAS 发表于 2014-9-22 11:24:48

感谢楼主了.第一次用IIS7.5终于解决了这个事.

yuvista 发表于 2011-6-28 23:18:41

楼主好人正需要

幽蓝冰魄 发表于 2011-6-29 10:37:13

启用 <rewrite> 节,好像需要 rewrite.dll 组件。

Altair 发表于 2013-1-19 19:52:17

有用啊

Altair 发表于 2013-1-19 20:15:50

I find:必须在服务器端新建web.config文件,输入相关内容.如果是在本地建立,再通过ftp上传,会出现500错误,虽然内容和名称完全一样!

grilas 发表于 2013-3-22 16:24:07

HTTP 错误 500.19 - Internal Server Error
无法访问请求的页面,因为该页的相关配置数据无效。


我的怎么报这个错误啊!!!

erebus 发表于 2013-4-7 22:36:53

正好需要,mark,谢谢

mafly 发表于 2013-5-4 11:55:53

學習中
先拜讀了

winds_ha 发表于 2013-7-30 09:48:29

很有用!{:1_1:}

冷木言 发表于 2013-8-2 15:37:15

正在测试IIS6
页: [1] 2
查看完整版本: IIS7.5 去除 index.php web.config配置文件