`

整理 IIS7配置web.config

阅读更多

会持续添加一些内容。。。。

web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
	<httpErrors>
		<remove statusCode="404" subStatusCode="-1" />
		<!--统一修改为404.asp,因为这样返回状态码才会是404-->
		<error statusCode="404" prefixLanguageFilePath="" path="/404.asp" responseMode="ExecuteURL" />
	</httpErrors>
</system.webServer>
<system.webServer>
	<!-- http://www.xxx.com 替换为对应的网站,带www-->
	<httpRedirect enabled="false" destination="http://www.xxx.com" exactDestination="false" childOnly="false" httpResponseStatus="Permanent" />
	<!--启用Gzip压缩-->
	<urlCompression doStaticCompression="true" doDynamicCompression="false" />
	<defaultDocument>
		<files>
			<clear />
			<add value="index.html" />
			<add value="index.php" />
			<add value="index.htm" />
			<add value="index.asp" />
		</files>
	</defaultDocument>
</system.webServer>
<system.webServer>
	<rewrite>
		<rules>
			<rule name="WWW Redirect" stopProcessing="true">
				<match url=".*" />
				<conditions>
					<!--xxx.com,替换为对应的网站,不带www-->
					<add input="{HTTP_HOST}" pattern="^xxx.com$" />
				</conditions>
				<!-- http://www.xxx.com 替换为对应的网站,带www-->
				<action type="Redirect" url="http://www.xxx.com/{R:0}" redirectType="Permanent" />
			</rule>
			<rule name="Default Index">
				<match url="^index.html$" ignoreCase="false" />
				<action type="Redirect" url="/" appendQueryString="false" redirectType="Permanent" />
			</rule>
			<rule name="Mobile Jump">
				<match url="^(.*)$" />
				<conditions logicalGrouping="MatchAll">
					<add input="{HTTP_USER_AGENT}" pattern="nokia|iphone|android|motorola|symbian|sony|ericsson|mot|samsung|htc|sgh|lg|sharp|sie-|philips|panasonic|alcatel|lenovo|ipod|blackberry|meizu|netfront|ucweb|windowsce|palm|operamini|operamobi|opera|openwave|nexusone|cldc|midp|wap|mobile" />
				</conditions>
				<!-- 输入要跳转的手机站点 -->
				<action type="Redirect" url="http://m.xxx.com/{R:1}" redirectType="Found" />
			</rule>
		</rules>
	</rewrite>
</system.webServer>
</configuration>

 

web.config 功能的说明:

  • 找不到页面设置为 404.asp 页面
  • 启用Gzip压缩,仅压缩静态页面,不压缩动态页面
  • 当客户端请求服务器时返回的默认文档顺序
  • 不带www的域名跳转到带www
  • 首页默认去掉index.html
  • 手机跳转到对应的手机路径

 首页301跳转指定的页面,其他页面301跳转对应的路径

<rule name="Index Redirect" stopProcessing="true">
	<match url="(^index.html$)|(^$)" />
	<action type="Redirect" url="http://www.xxx.com/index/" redirectType="Permanent" />
</rule>
<rule name="Path Redirect" stopProcessing="true">
	<match url="^(?!index.html).+$" />
	<action type="Redirect" url="http://www.xxx.com/{R:0}" redirectType="Permanent" />
</rule>

 

整站301跳转对应的路径

<rule name="301Redirect" stopProcessing="true">
	<match url="^(.*)$" />
	<action type="Redirect" url="http://m.xxx.com/{R:0}" redirectType="Permanent" />
</rule>	

 

不包含某字符串的URL,301跳转对应路径,str 改为该字符串

<rule name="Path Redirect" stopProcessing="true">
	<match url="^((?!str).)*$" />
	<action type="Redirect" url="http://www.xxx.com/{R:0}" redirectType="Permanent" />
</rule>
<!-- 多个字符串的匹配方式 -->
<match url="^((?!(str1|str2|str3)).)*$" />

 

这是用来测试 web.config 的match url 正则是否通过,匹配的是路径部分。

<script type="text/javascript">
function isUrlMatch(url){
	//var reg = new RegExp('/+');
	//var reg = new RegExp('^(?!index).+$');
	//var reg = new RegExp('^(index)$');	
	var reg = new RegExp('^(?!index.html).+$');
	var bool = url.match(new RegExp(reg));
	if(bool){
		document.write("通过");
	}else{
		document.write("不通过");
	}
}
isUrlMatch("dd/index.html");
</script>

 

 统一隐藏路径的方法,'demo'改为要隐藏的路径

<?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="demo/{R:1}" />
		</rule>
	</rules>
</rewrite>
</system.webServer>
</configuration>

 

配置伪静态,将织梦的动态标签页面php变成html页面显示

<rule name="weather1" stopProcessing="true">
	<match url="tags/([^-]+).html$" ignoreCase="true" />
	<conditions logicalGrouping="MatchAll">
		<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
		<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
	</conditions>
	<action type="Rewrite" url="/tags.php?/{R:1}" appendQueryString="false" />
</rule>
<rule name="weather2" stopProcessing="true">
	<match url="tags/([^-]+)-([0-9]+).html$" ignoreCase="true" />
	<conditions logicalGrouping="MatchAll">
		<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
		<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
	</conditions>
	<action type="Rewrite" url="/tags.php?/{R:1}/{R:2}" appendQueryString="false" />
</rule>

 

 指定域名来手机跳转

<rule name="wwwdemocom">
	<match url=".*" />
	<conditions logicalGrouping="MatchAll">
		<add input="{HTTP_HOST}" pattern="^www.demo.com$" />
		<add input="{HTTP_USER_AGENT}" pattern="nokia|iphone|android|motorola|symbian|sony|ericsson|mot|samsung|htc|sgh|lg|sharp|sie-|philips|panasonic|alcatel|lenovo|ipod|blackberry|meizu|netfront|ucweb|windowsce|palm|operamini|operamobi|opera|openwave|nexusone|cldc|midp|wap|mobile" />
	</conditions>
	<action type="Redirect" url="http://m.demo.com/" redirectType="Found" />
</rule>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1
0
分享到:
评论

相关推荐

    WebService发布过程及常见问题(含Win7)整理.pdf

    3. 如果是IIS配置问题,检查IIS应用程序池的.NET Framework版本设置,确保与Web服务项目匹配。 4. 使用IIS或VS自带的诊断工具进行排查,例如VS的“调试器”或IIS的日志记录功能。 总的来说,发布和维护WebService...

    服务器配置步骤1[整理].pdf

    2. **IIS配置**: - 在IIS中新建两个应用程序池,分别命名为`.NET1.0`和`.NET2.0`。 - 创建一个名为`LIBYDD2`的新网站,并设置其端口和根目录。 - 新建虚拟目录`LIBY`,并配置相应的权限和应用程序池。 - 修改`...

    IIS6.0所有确实文件大全

    7. **web.config**: 这是IIS的配置文件,用于定义网站的设置和规则。 8. **ntlmsspi.dll**: 实现NT LAN Manager (NTLM)身份验证协议的动态链接库。 9. **kerberos.dll**: 支持Kerberos身份验证协议的文件,用于更...

    c#UrlRewriter伪静态(UrlRewriter.dll和Intelligencia.UrlRewriter.dll)

    最近研究了一下伪静态,网上资料确实是比较多,我经过大量的测试,现整理两种方法进行伪静态 第一种方法需引用UrlRewriter.dll,请参考Web1.config部署 第二种方法需引用Intelligencia.UrlRewriter.dll,请参考Web....

    IIS6安装过程中,需要的一些文件

    描述中的"(20090919收集)"提示这些文件是在特定时间点整理的,可能包括了当时IIS6安装所需的最新补丁、更新或特定配置文件。由于IIS的更新和安全修复通常通过Windows Update或微软官方网站发布,因此这个集合可能...

    IIS+PHP+MySql配置手册

    《IIS+PHP+MySQL配置手册》是一份详细的指南,主要针对Windows Server 2003环境下搭建基于IIS的Web服务器,同时结合PHP和MySQL数据库进行网站开发和管理的流程。以下是根据标题、描述和部分内容整理出的关键知识点:...

    ASP.NET Web程序设计 (2)..zip

    6. **ASP.NET应用结构**:包括Web.config配置文件、Global.asax的应用程序生命周期管理和路由规则。 7. **安全与身份验证**:讲解了ASP.NET的安全特性,如身份验证、授权和防止跨站脚本攻击。 8. **性能优化**:提到...

    Arcgis学习资料-整理

    确保IIS中的虚拟目录指向正确的arcgisoutput文件夹,这通常是由于IIS配置错误导致地图预览失败,即使地图服务已经发布。 3. **ArcGIS Server配置中常见问题** - **无法通过Arccatalog连接服务器的ArcGIS Server** ...

    LR常见问题整理汇总

    在 IIS 中找到 Web.Config 文件,在 &lt;system.web&gt;….&lt;/system.web&gt; 节加 入 后再次录制,就不会出现中文乱码问题了。 3.HTML-based script 与 URL-based script 的脚本有什么区别? 使用“HTML-based script”的...

    ASP.NET技术文档又一次的整理

    比如,理解IIS(Internet Information Services)服务器的角色,以及如何配置web.config文件来控制应用程序的行为。你还会学习到如何使用Visual Studio进行开发,创建和管理数据库,以及如何使用LINQ(Language ...

    asp.net实际开发笔记整理

    8. **部署和配置**:了解IIS(Internet Information Services)配置、发布设置以及web.config文件的修改是实际开发中不可或缺的部分。 9. **性能优化**:包括缓存策略、页面压缩、异步编程、数据库查询优化等,都是...

    IISTR

    4. **启用和配置IISTrace**:管理员可以通过IIS管理控制台或Web.config文件来启用和配置IISTrace,设置跟踪级别(如警告、信息或详细)和存储路径。 5. **分析日志和追踪数据**:收集到的IISTrace数据通常需要使用...

    ASP.NET应用中十大常见的潜在问题

    - 在web.config文件中通过`&lt;roleManager enabled="true" cacheRolesInCookie="true" /&gt;`等配置项来调整角色管理策略。 - 根据具体需求选择合适的存储提供程序,例如数据库或文件系统。 #### 7. Profile特性使用...

    ASP.NET培训讲义(根据多方资料整理)

    6. **部署和配置**:讲解如何将ASP.NET应用程序部署到IIS服务器,以及如何配置web.config文件以适应不同环境。 7. **ASP.NET Core**:简述ASP.NET Core的特点,它是跨平台的,支持.NET Core运行时,具有高性能和...

    ASP.NET常用代码精华( 自己收集的) (不是我哈~)

    14. **部署与配置**:了解IIS设置、Web.config配置文件的修改,以及发布和部署ASP.NET应用程序的流程。 这个"ASP.NET学习积累的代码—太多了够你学的了"可能包含了上述各种技术的实际代码示例,是学习和提升ASP.NET...

    ASP.NET技术精粹

    - 配置Web.config文件,处理IIS设置,进行Web应用的发布和更新。 10. **Web服务与API** - 创建和消费SOAP与RESTful Web服务,了解WCF(Windows Communication Foundation)。 11. **ASP.NET Core** - ASP.NET的...

    WCF学习笔记,自己整理,xps格式

    2. **配置服务**: 在配置文件(Web.config或App.config)中定义服务的终结点,包括地址、绑定和合同。 3. **发布服务**: 使用ServiceHost类启动服务,或者在IIS中部署。 **WCF客户端调用** 1. **生成代理**: 使用...

    基于ASP.net的销售分析系统源码.zip

    6. **配置文件**:web.config,包含了应用程序的配置信息,如连接字符串、安全性设置等。 7. **图片和资源文件**:如logo、图标等静态内容。 8. **部署文件**:可能包含IIS相关的部署设置或发布文件,用于将应用部署...

    .net学习实用笔记

    通常,我们会在 `web.config` 文件中配置 Session 的状态管理方式。 ```xml &lt;system.web&gt; &lt;/system.web&gt; ``` 这里的 `&lt;sessionState&gt;` 节点配置了 Session 的模式为 “InProc”,表示 Session 数据将存储在...

Global site tag (gtag.js) - Google Analytics