Web.config set 301 and 404 jump, set the 404 return status code to 404

When the website is deployed and online, it is generally necessary to set the domain name without www to redirect 301 to the page with www, and 404 error jump page, then how to change it in the iis environment

1. Web.config sets 301 redirection without www domain name to the domain name with www

   In the web.config file, add the following code in the middle of the code <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 set 404 error jump, and set the 404 return status code to 404

 In the web.config file, add the following code in the middle of the code <system.webServer> </system.webServer>

 <httpErrors errorMode="DetailedLocalOnly">
         <remove statusCode="404" />
         <error statusCode="404" path="/404.aspx" responseMode="ExecuteURL"/>
       </httpErrors> 

Note : If it is an asp website, change the 404 page to 404.aspx format and add the following code to the header to set the return status code to 404

<%
Response.Status = "404 Not Found"
%> 

If it is a php website, change the 404 page to 404.php format and add the following code to the header to set the return status code to 404

<?php

        header(”HTTP/1.0 404 Not Found”);

?>

Guess you like

Origin blog.csdn.net/qq_39339179/article/details/111028240