在网站部署上线的时候一般都需要设置域名不带www的301从定向到带www,和404错误跳转页面,那么在iis环境下改该如何设置呢
1、Web.config 设置不带www域名301重定向到带www的域名
在web.config文件中,代码<system.webServer> </system.webServer> 中间添加如下代码
<rewrite>
<rules>
<rule name="WWWR" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^xxxxx.com$" />
</conditions>
<action type="Redirect" url="http://www.xxxxx.com/{R:0}" />
</rule>
</rules>
</rewrite>
2、Web.config 设置404错误跳转,并设置404返回状态码为 404
在web.config文件中,代码<system.webServer> </system.webServer> 中间添加如下代码
<httpErrors errorMode="DetailedLocalOnly">
<remove statusCode="404" />
<error statusCode="404" path="/404.aspx" responseMode="ExecuteURL"/>
</httpErrors>
注意: 如果是asp网站,把404页面改为404.aspx格式在头部添加 如下代码即可 设置返回状态码为404
<%
Response.Status = "404 Not Found"
%>
如果是php网站的话把404页面改为404.php格式在头部添加 如下代码即可 设置返回状态码为404
<?php
header(”HTTP/1.0 404 Not Found”);
?>