IIS7.5使用web.config设置伪静态的二种方法
2013-11-07 15:41
771 查看
近几天公司里开发的项目有几个运行在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>
第二种方法: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>
下面是补充:
IIS 7和IIS 7.5及以后的版本估计都会使用web.config来实现伪静态规则,于是我们以前的伪静态文件必须更改。网上找了一圈,还没有发现比较全面的web.config伪静态规则,于是我们这里整理一份,供初次使用的朋友参考。
实现普通页面、带一个数字参数页面和带两个参数页面的伪静态!
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Index" stopProcessing="true"> <match url="^index.html" /> <action type="Rewrite" url="index.php" /> </rule> <rule name="Rule1" stopProcessing="true"> <match url="^news_([0-9]+).html" /> <action type="Rewrite" url="news.php?nid={R:1}" /> </rule> <rule name="Rule2" stopProcessing="true"> <match url="news_list_([0-9]+)_([0-9]+).html" /> <action type="Rewrite" url="news_list.php?nid={R:1}&page={R:2}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
IIS 7.5通过web.config实现301重定向的方法,将不带www的域名转向到带www的域名上!
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Redirect" stopProcessing="true"> <match url=".*" /> <conditions> <add input="{HTTP_HOST}" pattern="^chuangluo.com$" /> </conditions> <action type="Redirect" url="http://www.chuangluo.com/{R:0}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
由于我们的网站使用了转义字符,因此在实际使用的时候,大家不可以直接复制以上代码。请复制粘贴到Dreamweaver等编辑器后,使用替换功能把双引号全部替换为英文状态下的双引号,然后再修改rule标签内的内容就可以了,跳转的地方请更改为自己的网址即可。
需要注意的地方是以前httpd.ini和.htaccess支持网址中两个参数用&符号链接,在web.config中是不支持的,需要将这个符号更改为&才能正常使用。由于我们目前只有一台这种类型的服务器使用经验,有可能存在不足,如有更多更全面的资料,欢迎交流学习!
您可能感兴趣的文章:
相关文章推荐
- IIS7.5使用web.config设置伪静态的方法
- IIS7.5使用web.config设置伪静态的二种方法(转)
- [强烈推荐] thinkphp iis7.5 win2008 上 设置虚拟静态 错误的解决方法 web.config
- IIS 7.5伪静态文件web.config编写规则及301重定向方法
- 【视频】自然框架之分页控件的使用方法(二) 下载、DLL说明和web.config的设置
- 【视频】自然框架之分页控件的使用方法(二) 下载、DLL说明和web.config的设置
- IIS使用 URL Rewrite Module 2.0组件 设置伪静态的方法
- [Windows Server 2008] IIS配置伪静态方法(Web.config模式的IIS rewrite)
- WIN8 、WIN7 下IIS7.5、IIS8 的rewrite 伪静态功能设置方法
- WIN8 、WIN7 下IIS7.5、IIS8 的rewrite 伪静态功能设置方法
- [备忘]IIS 7.5运行.aspx出现“由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面。”错误解决方法
- 图解修改IIS web.config配置文件增设置默认文档的方法
- IIS 之 通过 Web.config 修改文件上传大小限制设置方法
- IIS7.5提示无法写入配置文件web.config的解决方法
- IIS 7.5 设置允许下载exe文件的解决方法
- IIS Express web.config 设置(〇)
- iisnode特定设置(web.config中管理)
- web.config/app.config敏感数据加/解密的二种方法
- C# asp.net IIS 在web.config和IIS中设置Session过期时间
- 将所有程序设置XML集中到一个单独XML配置文件的方法:使用appSettings元素的configSource元素