Cartika

Welcome, Guest Login

Support Center

Redirect non www domain to www in classic asp

Last Updated: Jun 09, 2014 06:16PM EDT
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"-->

Contact Us

sales@cartika.com
https://cdn.desk.com/
false
desk
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete