Solved

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

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Lync server 2013 or Skype for business Backup Service Error ID 4049 – After File Share Migration
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

21 Experts available now in Live!

Get 1:1 Help Now