How to do a 301 redirect in ASP and IP Canonicalization

How to do a 301 redirect in ASP and IP Canonicalization

301 redirect is one the method used for website redirection. The main purpose is usually to tell the search engine crawlers that a specific page had been moved and the index should be updated.

To add a redirection code to your ASP page, simply paste the following code :

<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.YourNewURL.com/"
%>
Generally, you should put the code at the very top of the ASP file. The code above will only work on an ASP Page. To do a 301 redirect on a standard HTML file will be a bit more complicated. A URL rewrite module such as ISAPI REWRITE will be required. Your host may also be able to set it via IIS.

IP Canonicalization

Your sites IP address should also be redirected to your site's domain name.
If not, this could cause duplicate content problems if a search engine indexes your site under both its IP and domain name.

You can add this code below into your existing web.config file :

<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="IP Hit" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="xxx.xxx.xxx.xxx" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
NOTE : Please change the xxx.xxx.xxx.xxx to your site IP address.
Please also change the www.example.com to your domain name.


Times Viewed:
3267
Added By:
Wilson Keneshiro
Date Created:
3/24/2011
Last Updated:
3/26/2015