IIS设置ThinkPHP伪静态

官方默认提供了.htaccess文件,不过这个文件仅能在Apache环境下生效,如果您的WEB服务器使用的IIS,那么伪静态规则需要做一些修改或调整。

首先需要确保的是您的ThinkPHP URL模式为2,然后添加下面的规则。

IIS 6规则

[ISAPI_Rewrite]
# Defend your computer from some worm attacks
RewriteCond %{REQUEST_URI} !^.*(.css|.js|.gif|.png|.jpg|.jpeg|.xml|.php)
RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]
RewriteRule (?!/index.php)(?!/admin.php)(?!/Admin/)(?!/Public/)(?!/install/)(?!/404/)(?!/plugin/)(?!/css/)(?!/images/)(?!/js/)(.*)$ /index.php?s=$1 [I]

IIS 7规则

将下面的配置文件添加到web.config文件中:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <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>
    </system.webServer>
</configuration>

标签: thinkphp

发表评论: