Solved

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

Posted on 2014-12-04
5
214 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
  • 3
5 Comments
 
LVL 32

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Prologue It is often required to host multiple websites on a single instance of IIS, mostly in development environments instead of on production servers. I am sure it is not much a preferred solution on production servers but this is at least a pos…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now