Redirect non www domain to www in classic asp

Redirect non www domain to www in classic asp

If you are running your site on classic .asp, on a IIS 6 web server. Here is a method you can use to forward all non www. requests to www.example.com.

Create a new file for example named: redirect.asp | and insert this code into the file redirect.asp

<%

svrHttps = request.servervariables("HTTPS")
svrHost = request.servervariables("HTTP_HOST")
svrUrl = request.servervariables("URL")
svrQueryString = request.servervariables("QUERY_STRING")


IF left(svrHost,4) <> "www." THEN


IF svrHttps = "off" THEN
svrNewUrl = "http://www./"
ELSE
svrNewUrl = "https://www./"
END IF


svrNewUrl = svrNewUrl & svrHost & svrUrl
svrNewUrl = replace(svrNewUrl,"default.asp","")
svrNewUrl = replace(svrNewUrl,"index.asp","")


IF len(svrQueryString) > 0 THEN
svrNewUrl = svrNewUrl & "?" & svrQueryString
END IF


response.status = "301 Moved Permanently"
response.addheader "Location", svrNewUrl
response.end

END IF

%>

Then you will want to include the redirect.asp file in your main index page, such as index.asp or default.asp. Include this line of code in the main websites index page:

<!--#include file="redirect.asp"-->
    • Related Articles

    • How do I enable detailed errors in classic ASP?

      You can enable detailed error messages for your classic ASP site defaulted to Windows/IIS by using a web.config file with the following: <configuration> <system.webServer> <httpErrors errorMode="Detailed" /> </system.webServer> </configuration> Note: ...
    • How do I enable detailed errors in classic ASP?

      You can enable detailed error messages for your classic ASP site defaulted to Windows/IIS by using a web.config file with the following: <configuration> <system.webServer> <httpErrors errorMode="Detailed" /> </system.webServer> </configuration> Note: ...
    • SSL certificate not valid for domain.com but is for www.domain.com or vice versa

      Problem 1: I have purchased an SSL for domain.com, however, www.domain.com gives an SSL error Problem 2: I have purchased an SSL for www.domain.com, however, domain.com gives an SSL error -------------------------------- Most SSLs will provide a ...
    • Setting Domain to use Google Apps Email

      Information on setting up Google Apps in H-Sphere can be found at: http://www.google.com/support/a/bin/answer.py?hl=en&answer=61158 Once this is complete, you will want to turn off Mail Service under Domains -> Domain Settings (after ensuring that ...
    • How to copy an ASP/MS SQL site to a local machine

      Customer wants to copy his/her site to a local PC to show off in a "live" demo. You might want to look at http://www.w3schools.com/asp/asp_install.asp. It has a brief tutorial on how to set up Personal Web Server on a PC/Laptop which supports ASP ...