【原创】web.config文件的伪静态另类用法+IIS环境
1、自定义错误页面
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <httpErrors errorMode="Custom" existingResponse="Replace"> <clear /> <error statusCode="403" responseMode="ExecuteURL" path="/403.html" /> <error statusCode="404" responseMode="ExecuteURL" path="/404.html" /> <error statusCode="500" responseMode="ExecuteURL" path="/500.html" /> </httpErrors> </system.webServer> </configuration>
2、设置默认首页
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <defaultDocument enabled="true"> <files> <clear /> <add value="Default.htm" /> <add value="Default.asp" /> <add value="index.htm" /> <add value="index.html" /> <add value="iisstart.htm" /> <add value="default.aspx" /> </files> </defaultDocument> </system.webServer> </configuration>
3、设置mime类型
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <staticContent> <mimeMap fileExtension=".mp6" mimeType="video/x-flv" /> <mimeMap fileExtension=".mp7" mimeType="video/x-flv" /> </staticContent> </system.webServer> </configuration>
4、开启500详细错误提示
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <httpErrors errorMode="Detailed" /> </system.webServer> </configuration>
5、Html映射
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <handlers> <!--4.0映射--> <add name="list_2" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="C:WindowsMicrosoft.NETFrameworkv4.0.30319aspnet_isapi.dll" resourceType="File" preCondition="classicMode,runtimeVersionv4.0,bitness32" /> <!--2.0映射--> <add name="list_1" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="C:WindowsMicrosoft.NETFrameworkv2.0.50727aspnet_isapi.dll" resourceType="File" preCondition="classicMode,runtimeVersionv2.0,bitness32" /> </handlers> </system.webServer> </configuration> 注:*.html可以改为任意后缀
6、防盗链
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Vhost_AntiLeech" stopProcessing="true"> <match url=".(jpg|jpeg|png|gif|bmp)$" ignoreCase="true" /> <conditions> <add input="{HTTP_REFERER}" pattern="^(http://|https://)(www.)?(baidu.com|baidu123.com)($|/.*)" ignoreCase="true" negate="true" /> </conditions> <action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
7、301跳转
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Vhost_R301" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAny"> <add input="{HTTP_HOST}" pattern="^baidu.com$" /> </conditions> <action type="Redirect" url="http://www.baidu.com/{R:0}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
8、http跳转到https
<system.webServer> <rewrite> <rules> <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite> </system.webServer>
如果遇到其他问题可以私聊我