IIS7.5使用web.config设置伪静态的二种方法
发布时间:2015-11-30, 15:17:38 分类:Linux | 编辑 off 网址 | 辅助
图集1/2
正文 2600字数 447,806阅读
IIS7.5使用web.config设置伪静态方法近几天公司里开发的项目有几个运行在IIS7.5上,由于全站采用的是伪静态,因此从网上找到两两种方法来实现。这两种方法各有优势:
第一种比较灵活,只要把文件拷到根目录下,即可直接显示所有伪静态页面(适用于此伪静态规则的所有项目,如ThinkPHP),无需更改代码;
第二种适合有子目录时的伪静态,比如一个网站下有多个子网站且都要使用伪静态,那么就考虑使用第二种方法了,第一种会报错误。两种方法,自己根据情况使用吧(当然,并不是适用所有项目,可以根据项目的伪静态规则自行调整)。
以下是代码:
第一种方法: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>
Run code
Cut to clipboard
第二种方法:web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="规则 1" stopProcessing="true">
<match url="^includes/(.*)" />
<action type="Rewrite" url="includes\/{R:1}" />
</rule>
<rule name="规则 2" stopProcessing="true">
<match url="^(blog)/includes/(.*)" />
<action type="Rewrite" url="{R:1}/includes\/{R:2}" />
</rule>
<rule name="规则 3" stopProcessing="true">
<match url="^(blog)/(.*).html(.*)" />
<action type="Rewrite" url="{R:1}/index.php\/{R:2}.html{R:3}" />
</rule>
<rule name="规则 4" stopProcessing="true">
<match url="^(.*).html(.*)" />
<action type="Rewrite" url="index.php\/{R:1}.html{R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Run code
Cut to clipboard
(支付宝)给作者钱财以资鼓励 (微信)→
有过 1 条评论 »
选择.htaccess
Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]