windows2003 PHP IIS URL重写去掉index.php

时间:2021-08-31 19:56:09

1:要是在版本比较高的IIS环境下,URL重写只需要在站点跟配置web.config文件就可以了,当然在使用IIS建站点的时候站点默认就会建立以个web.config文件(thinkphp框架,对应的

    'URL_ROUTER_ON' => true, //URL路由
    'URL_MODEL' => 2,)这里就不讲了......

这个是我的web.config配置(去除index.php)

<?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>
<remove value="index.html" />
<remove value="iisstart.htm" />
<remove value="index.htm" />
<remove value="Default.asp" />
<remove value="Default.htm" />
<add value="index.html" />
<add value="index.php" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
2:IIS版本比较低的话要URL重写就要使用到ISAPI_Rewrite,来实现URL重写

安装ISAPI_Rewrite3

windows2003 PHP IIS URL重写去掉index.php

httpd.conf 里面配置URL重写完整代码....

# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.104

RewriteEngine On
RewriteCompatibility2 On
RepeatLimit 32
RewriteBase
# unsupported directive: [ISAPI_Rewrite]

# 3600 = 1 hour
# unsupported directive: CacheClockRate 3600


# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# RewriteRule ^/httpd(?:\.ini|\.parse\.errors).* [F,I,O]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ /index.php?s=$1 [I]
 

简单说明:与上面URL重写是一样的效果(去掉index.php)......

<pre name="code" class="php">//这两行代码是省去一些样式等等被 Rewrite了...
RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d
//去掉index.php的代码URL重写
RewriteRule (.*)$ /index.php?s=$1 [I]

 
ISAPI_Rewrite设置OK了 

IIS添加筛选器windows2003 PHP IIS URL重写去掉index.php

打开Helicon Manager(安装ISAPI_Rewrite文件目录的文件)

这是就可以看到IIS已经加载我们之前配置的httpd.conf 文件

windows2003 PHP IIS URL重写去掉index.php

当前我可以点击Edit进行编辑

要是点击Import from v2.0的话:显示如下

windows2003 PHP IIS URL重写去掉index.php

这里也是ISAPI_Rewrite安装后的目录里面的配置文件...可能有些童鞋网上下载可能没这个文件....不过不要紧...直接在httpd.conf文件里编辑就行了

要是存在httpd.ini文件的时候这里打开后会备份之钱的httpd.conf配置文件根据httpd.ini的配置生成新的httpd.conf配置文件

这是我的httpd.ini文件(去掉index.php)

[ISAPI_Rewrite]

# 3600 = 1 hour
CacheClockRate 3600

RepeatLimit 32

# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
#RewriteRule ^/httpd(?:\.ini|\.parse\.errors).* [F,I,O]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ /index.php?s=$1 [I]


补充说明:上面试的是php5.2的版本,当换成php5.4版本的时候重写失败.....

原因:可以查看跳转地址日志,没有识别出域名....
windows2003 PHP IIS URL重写去掉index.php

PHP5.4路由代码....
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.104

RewriteEngine On
RewriteCompatibility2 On
RepeatLimit 32
RewriteBase
# unsupported directive: [ISAPI_Rewrite]

# 3600 = 1 hour
# unsupported directive: CacheClockRate 3600


# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# RewriteRule ^/httpd(?:\.ini|\.parse\.errors).* [F,I,O]
#RewriteCond %{REQUEST_FILENAME} ^!-f$
#RewriteCond %{REQUEST_FILENAME} ^!-d$
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://192.168.0.109/index.php$1 [NC]
RewriteLog "E:\Program Files\Helicon\ISAPI_Rewrite3\rewrite.log"
RewriteLogLevel 9