How to setup a 301 redirect so your site does not show default.asp as the homepage

How to setup a 301 redirect so your site does not show default.asp as the homepage

Below are instructions on how to set up a 301 redirect so default.asp is not displayed as your homepage:

http://www.yoursite.com/default.asp

To :

http://www.yoursite.com/

Your web server will need to have ISAPI Rewrite installed for this change to work.

Please follow the steps below:

1. Open file default.asp using notepad or text editor.

2. Locate this code :

<%
'*********************************************************************************
' 7.00
' 1 Dec 2009
' main page
'*********************************************************************************


3. Directly below it, insert the following code:

'702 - 2012.11.01 - Enhancement: SEO - To remove default.asp from SEO link
if instr(lcase(request.servervariables("HTTP_X_REWRITE_URL")),"default.asp") > 0 then
dim replacescriptname
replacescriptname = lcase(request.servervariables("HTTP_X_REWRITE_URL"))

'702 - 2013.03.01 - Bug Fix: Remove default.asp is not working with subfolder shopping cart
dim replacexmysite
replacexmysite = request.ServerVariables("HTTP_HOST")
replacescriptname = "http://" & replacexmysite & replace(replacescriptname,"default.asp","")

Response.Clear
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", replacescriptname
Response.Flush
Response.End
end if


4. Save the file and upload to your site.

If the above coding method is not working, then you can try another alternative using web.config rewrite code.

Please note, using this second alternative method, your server needs to have IIS 7 and above and also have Rewrite module installed.

1. Open web.config file using notepad or text editor, which is usually located in the root of your site.

2. Append this code into the file, inside the <rewrite><rules> </rules></rewrite>:

<rule name="Default Redirect" stopProcessing="true">
<match url="^default\.asp$" />
<action type="Redirect" url="/" redirectType="Permanent" />
</rule>

So your complete code would look like e.g. :

<rewrite>
<rules>
<rule name="Default Redirect" stopProcessing="true">
<match url="^default\.asp$" />
<action type="Redirect" url="/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>

3. Save the web.config file and upload to your site.

For more information about IIS rewrite, you can also refer to this link:

http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module


Times Viewed:
8516
Added By:
wilson
Date Created:
10/31/2012
Last Updated:
3/26/2014