Solved

IIS6 asp redirect for http:// to http://www.

Posted on 2014-12-04
5
223 Views
Last Modified: 2014-12-04
Hi Experts

Please can you advise the simplest way to get a redirect put in place for a classic ASP site running on IIS6 on a Windows 2003 server, so that whenever someone tries to visit, for example, http://abc.com (without the www) it redirects them automatically to http://www.abc.com

I can also set ASP.net to run on this site, if that helps.

I would like a solution that does not require 3rd party software.

500 points.

Thanks
0
Comment
Question by:wesmanbigmig13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 40482140
IIS7 has a built in url rewriter, since you're using IIS6, you would need to install something like isapi rewrite for the same type of functionality. since you're not seeming like you want to use a third party component, your only viable option is to write code.

check out this tutorial for the full reference to the code below:

<%

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

%>

Open in new window


if you have an include file that's near the top of each page, you could put it in there (such as a header or a common library file you load for each page), that way you don't need to touch each file to implement this functionality
0
 

Author Comment

by:wesmanbigmig13
ID: 40482166
Minor update / extra code required - had to declare each of the variables, but once I did that it worked perfectly.

Dim svrHttps
Dim svrHost
Dim svrUrl
Dim svrQueryString
Dim svrNewUrl

Thank you!
0
 
LVL 13

Expert Comment

by:Surone1
ID: 40482167
it's been too long for me to remember but the code might be able to be placed in global.asa . that should run for every (asp?) page. not sure if you neeed to configure IIS for it.
0
 

Author Comment

by:wesmanbigmig13
ID: 40482169
I've requested that this question be closed as follows:

Accepted answer: 0 points for wesmanbigmig13's comment #a40482166

for the following reason:

Worked perfectly after declaring the variables in the code supplied.
0
 

Author Closing Comment

by:wesmanbigmig13
ID: 40482170
Perfect, thank you
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question