Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!

 



Are you a Google Analytics enthusiast?

Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE! 

 



 

 www.CustomReportSharing.com 

From the folks who brought you High Rankings!


Sponsored Content

 

 
 

Photo
- - - - -

301 Redirects On Windows 2000 Iis


  • Please log in to reply
25 replies to this topic

#16 jehochman

jehochman

    Jonathan Hochman

  • Active Members
  • PipPipPipPipPipPipPip
  • 1,555 posts
  • Location:Connecticut - Land of Steady Habits

Posted 25 July 2006 - 12:12 AM

Thanks Ian!

Your solution is very helpful for dealing with a few pages, and helps my understanding of the situation. The developer has renamed about 100 pages (they contacted me afterwards). First, the original pages don't exist on the new server, so we'd have to create them, and then set up each of the redirects by hand. Of course, I don't have direct access to the server so I'd have to count on somebody else, which worries me.

I can build an Excel spreadsheet with a map of the redirects, and turn it into a series of ISAPI_rewrite commands. The software is $69, and the install is quick. It seems like this solution will take less time, and make it easy to modify the redirects by editing the http.ini file remotely. No administrator required.

#17 Mohit.

Mohit.

    HR 3

  • Active Members
  • PipPipPip
  • 90 posts
  • Location:Gujarat, India.

Posted 29 July 2006 - 02:03 AM

I have a asp site. And i have windows server and web server is IIS.

For doing 301 redirection of my site's domain.com(non www) to www.domain.com(with www), what i should use.

Code given by chrishirst or by the tips given at mcanerin's site. Which is better.

And if i want to use chrishirst's code, where i have to put it??? In head section... Probabely i think.

Edited by Mohit., 29 July 2006 - 02:10 AM.


#18 seadog

seadog

    HR 3

  • Active Members
  • PipPipPip
  • 88 posts

Posted 12 March 2007 - 11:38 PM

My client has a second domain 'mirrored' onto his main domain. To try and compensate, I added this line to the script
[codebox]if(Request.ServerVariables("SERVER_NAME") <> "justassociates.com") then bRedirect = true[/codebox]

I get an error back in my browser that says:

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete

* This problem can sometimes be caused by disabling or refusing to accept
cookies.

Any ideas??

Thank You

QUOTE(chrishirst @ Jan 12 2005, 12:53 PM) View Post
In ASP, Maybe I'll write a .net one some day (or maybe not biggrin.gif )
CODE
dim hostname
dim pathinfo
dim bRedirect
dim MainDomain

hostname = request.servervariables("HTTP_HOST")
pathinfo = request.servervariables("PATH_INFO")
MainDomain = "www.domain.com"
if pathinfo <> "" then
    if instr(lcase(pathinfo),"default.asp") > 0 or instr(lcase(pathinfo),"index.asp") > 0 or instr(lcase(pathinfo),"index.aspx") > 0 then
     MainDomain = MainDomain &"/" & mid(pathinfo,2,instrrev(pathinfo,"/")-1)
    else
  MainDomain = MainDomain & pathinfo
    end if
else
     MainDomain = MainDomain & "/"
end if
if left(hostname,instr(hostname,".")) <> "www." then bRedirect = true
if bRedirect then
    response.status = "301 Moved Permanently"
    response.addheader "Location", "http://" & MainDomain
    response.end
end if


put it at the top of every ASP page as an include every page and folder will be corrected.

Raphael, If IIS is left to it's own devices all the versions will return a 200 response so looks like duplicate sites (www & non-www).



#19 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 5,879 posts
  • Location:Blackpool UK

Posted 13 March 2007 - 02:56 PM

depends on where you added the line

it should go in above

if left(hostname,instr(hostname,".")) <> "www." then bRedirect = true


do take note that this code does not take querystrings into account though it could be added.



#20 seadog

seadog

    HR 3

  • Active Members
  • PipPipPip
  • 88 posts

Posted 13 March 2007 - 05:24 PM

Thanks Chris

I had added it below that line. I'll fix it up and post back after I test

Thanks

#21 seadog

seadog

    HR 3

  • Active Members
  • PipPipPip
  • 88 posts

Posted 13 March 2007 - 07:34 PM

QUOTE(chrishirst @ Mar 13 2007, 01:56 PM) View Post
depends on where you added the line

it should go in above

if left(hostname,instr(hostname,".")) <> "www." then bRedirect = true
do take note that this code does not take querystrings into account though it could be added.


hmm... I placed the new line above the line you pointed out and I am still getting the browser error when I go to the mirror domain (which would return a 200 normally if I wasn't messing with the ASP script. Here is my exact code. Any other ideas? It would appreciated.
Thank You

[codebox]<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
dim hostname
dim pathinfo
dim bRedirect
dim MainDomain
dim domain

hostname = request.servervariables("HTTP_HOST")
pathinfo = request.servervariables("PATH_INFO")
domain = Request.ServerVariables("SERVER_NAME")

MainDomain = "www.justassociates.com"
if pathinfo <> "" then
if instr(lcase(pathinfo),"default.asp") > 0 or instr(lcase(pathinfo),"index.asp") > 0 or instr(lcase(pathinfo),"index.aspx") > 0 then
MainDomain = MainDomain &"/" & mid(pathinfo,2,instrrev(pathinfo,"/")-1)
else
MainDomain = MainDomain & pathinfo
end if
else
MainDomain = MainDomain & "/"
end if

if(domain <> "justassociates.com") then bRedirect = true
if left(hostname,instr(hostname,".")) <> "www." then bRedirect = true
if bRedirect then
response.status = "301 Moved Permanently"
response.addheader "Location", "http://" & MainDomain
response.end
end if
%>[/codebox]

#22 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 5,879 posts
  • Location:Blackpool UK

Posted 14 March 2007 - 05:27 AM

After a serious look, your added code could create a locked loop.

There is no need for the second variable of domain. You should also be aware of the differences between HTTP_HOST and SERVER_NAME.
Usually both will return the same value, BUT depending on the configuration within a hosting datacentre, if it uses NAT routing or port routing through a firewall or DMZ for example, SERVER_NAME will return the routed name NOT the host header or DNS name which is the important bit from an external POV.

HTTP_HOST will return the DNS name (host header) of the server.

so instead of this;

if(domain <> "justassociates.com") then bRedirect = true

use;
CODE
if not (InStr(hostname,"justassociates.com") <> 0) then bRedirect = true

However be aware that if the hostname contains "justassociates.com" anywhere (for example "abc-justassociates.com") it will fail to redirect

and of course you could use;
if(hostname <> "justassociates.com") then bRedirect = true

However this would also redirect if you were using any sub-domains.

Additional code required to handle querystrings

CODE
        MainDomain = MainDomain & "/"
end if
' insert the lines below.
if request.servervariables("QUERY_STRING") <> "" then
MainDomain = MainDomain & "?" & request.servervariables("QUERY_STRING")
end if



#23 seadog

seadog

    HR 3

  • Active Members
  • PipPipPip
  • 88 posts

Posted 14 March 2007 - 02:00 PM

That makes sense Chris,
Thanks again for the input. I'll give it a go later today and post back results again.

thanks
Mike



#24 seadog

seadog

    HR 3

  • Active Members
  • PipPipPip
  • 88 posts

Posted 20 March 2007 - 09:39 PM

Sorry for the delay, this worked like a charm!! Thanks Chris



#25 seoqueen

seoqueen

    HR 1

  • Members
  • Pip
  • 1 posts

Posted 24 September 2008 - 10:14 AM

What about redirecting dynamic pages from a .NET platform to ASP static pages? plz help!

#26 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 5,879 posts
  • Location:Blackpool UK

Posted 25 September 2008 - 06:42 AM

might have a chance to given more information, other than that the answer is

Yes you can.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users