Solved

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

Posted on 2014-12-04
5
230 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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