IIS7.5下web.config伪静态设置方法

飘逸的风13年前 (2013-07-16)经验9912

近几天公司里开发的项目有几个运行在IIS7.5上,由于全站采用的是伪静态,因此从网上找到两两种方法来实现。这两种方法各有优势:第一种比较灵活,只要把文件拷到根目录下,即可直接显示所有伪静态页面(适用于此伪静态规则的所有项目,如ThinkPHP),无需更改代码;第二种适合有子目录时的伪静态,比如一个网站下有多个子网站(如:www.openkee.com/blog),且都要使用伪静态,那么就考虑使用第二种方法了,第一种会报错误。两种方法,自己根据情况使用吧(当然,并不是适用所有项目,可以根据项目的伪静态规则自行调整)。以下是代码:

第一种方法: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>

这两种方法也许不是最好的,但却是很实用。如果各位网友有更好的IIS7.5伪静态方法,可以在下面留言,好资源大家分享嘛!

 

相关文章

外贸商城开发经验分享

外贸商城开发经验分享

商城名称:Wholesale Gold Filled Jewelry, Gold Plated Jewelry, Cubic Zirconia Jewellery: JewelCZ 商城网址:htt...

一些可以查询IP地理位置、身份证所在地、手机归属地的接口

新浪的IP查询接口: 新浪的:https://counter.sina.com.cn/ip?ip=IP地址 返回Js数据,感觉不是很精确,可以把问号后面的去掉,直接返回本机对应的IP所在地...

Css之中英文左右(两端)对齐

<p>两端对齐</p> 英文对齐:<br> <div style="font-size:12px;width:300;text-align:justify...

Windows+Apache 访问速度慢的解决办法

1、首先在hosts文件中添加: C:\Windows\System32\drivers\etc 127.0.0.1       loca...

阿里云盘内测期间如何使用,申请并获得激活码?激活码分享!

阿里云盘内测期间如何使用,申请并获得激活码?激活码分享!

最近大家一定被阿里的两个网盘刷屏:阿里云网盘和teambition网盘。阿里云网盘注重的是个人用户,而teambition网盘,主要是企业或者多人协作。 目前这两款网盘...

阿里云盘和Teambition网盘到底有什么区别?

阿里云盘和Teambition网盘到底有什么区别?

阿里云盘和阿里云teambition网盘有什么区别?有很多人问这二个产品到底有什么区别?其实,这两款网盘主要在于定位和应用场景不同:Teambition定位是企业团队,阿里云盘定位是个人,可以根...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。