High Rankings Search Engine Optimization ForumHigh Rankings Advisor Search Marketing Newsletter

Welcome Guest ( Log In | Register )

Important Announcement: ***Need an Affordable SEO Website Review?***
2 Pages V   1 2 >  
Reply to this topicStart new topic
> 301 Redirects On Windows 2000 Iis, Specifically Home page variations
AlDugan
post Jan 12 2005, 01:01 PM
Post #1


HR 5
*****

Group: Active Members
Posts: 466
Joined: 20-November 03
User's local time:
Feb 9 2010, 12:14 PM
From: Keene, NH
Member No.: 1,387



Having trouble figuring out how to set up a 301 redirect on W2000 IIS 5. Specifically I want to redirect all variations of my home page...

CODE
http://www.mydomain.com/index.aspx
http://www.mydomain.com
http://mydomain.com
http://mydomain.com/

...to:

http://www.mydomain.com/


Since these are all obviously the exact same page when setting up the redirect I just end up in a loop.

Is there some way of accomplishing this?
Go to the top of the page
 
+Quote Post
Raphael
post Jan 12 2005, 01:07 PM
Post #2


The Limey Cowboy
******

Group: Active Members
Posts: 722
Joined: 17-December 04
User's local time:
Feb 9 2010, 02:14 PM
From: New England
Member No.: 5,984



Err, shouldn't IIS do all that automagically for you? I know apache does. You definitely shouldn't need 301 redirects for it.
Go to the top of the page
 
+Quote Post
Shane
post Jan 12 2005, 01:52 PM
Post #3


HR 6
******

Group: Active Members
Posts: 850
Joined: 4-May 04
User's local time:
Feb 9 2010, 02:14 PM
From: Atlanta, GA
Member No.: 3,454



1. I think this one will have to be done in the ASPX code. Don't think you can 301 at the file level in IIS.
2. No need to worry about this one. It's treated the same as the version with the forward-slash on the end of it.
3. Set up a separate web site in IIS with a host header of "mydomain.com" and have it permanently redirect users to "www.mydomain.com"
4. Same as #2
Go to the top of the page
 
+Quote Post
chrishirst
post Jan 12 2005, 01:53 PM
Post #4


HR 9
Group Icon

Group: Moderator
Posts: 4,356
Joined: 13-August 03
User's local time:
Feb 9 2010, 06:14 PM
From: Blackpool UK
Member No.: 492



In ASP, Maybe I'll write a .net one some day (or maybe not (IMG:http://www.highrankings.com/forum/style_emoticons/default/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).
Go to the top of the page
 
+Quote Post
Shane
post Jan 12 2005, 03:05 PM
Post #5


HR 6
******

Group: Active Members
Posts: 850
Joined: 4-May 04
User's local time:
Feb 9 2010, 02:14 PM
From: Atlanta, GA
Member No.: 3,454



Actually, I think that would throw IIS into an infinite loop. If IIS is serving the default file in the folder, request.servervariables("PATH_INFO") will return the the name of the file even if it wasn't specified in the URL.

Example:
CODE
For http://www.mydomain.com/
request.servervariables("PATH_INFO") returns "/index.aspx"
Go to the top of the page
 
+Quote Post
chrishirst
post Jan 12 2005, 04:11 PM
Post #6


HR 9
Group Icon

Group: Moderator
Posts: 4,356
Joined: 13-August 03
User's local time:
Feb 9 2010, 06:14 PM
From: Blackpool UK
Member No.: 492



quite correct,

that's why the "if (instr... )" line strips off the default doc name so it doesn't cause a locked loop.
Go to the top of the page
 
+Quote Post
Randy
post Jan 12 2005, 04:26 PM
Post #7


Convert Me!
Group Icon

Group: Admin
Posts: 17,377
Joined: 17-August 03
User's local time:
Feb 9 2010, 12:14 PM
Member No.: 551



(IMG:http://www.highrankings.com/forum/style_emoticons/default/offtopic.gif)

hmm... Chris I think we should probably restrict LiLo from this thread. I can hear the chanting already...

Follow the penguin - follow the penguin
Go to the top of the page
 
+Quote Post
Shane
post Jan 12 2005, 04:44 PM
Post #8


HR 6
******

Group: Active Members
Posts: 850
Joined: 4-May 04
User's local time:
Feb 9 2010, 02:14 PM
From: Atlanta, GA
Member No.: 3,454



QUOTE(chrishirst @ Jan 12 2005, 04:11 PM)
that's why the "if (instr... )" line strips off the default doc name so it doesn't cause a locked loop.

That's what I'm saying. The "if (instr... )" line will always return true, even if the URL itself doesn't have the default document specified.

CODE
Example 1:
http://www.mydomain.com/index.aspx
- request.servervariables("PATH_INFO") returns /index.aspx
- instr(lcase(pathinfo),"index.aspx") > 0 is true
- So redirects to http://www.mydomain.com/
(This is assuming bredirect=true is added to that block to actually get it to redirect.  Otherwise, it only redirects if the domain doesn't start with "www.")

Example 2: http://www.mydomain.com/
- request.servervariables("PATH_INFO") returns /index.aspx
- instr(lcase(pathinfo),"index.aspx") > 0 is true
- So redirects to http://www.mydomain.com/
- We're into an infinite loop now


I actually ran the code on my IIS server to make sure.
Go to the top of the page
 
+Quote Post
chrishirst
post Jan 12 2005, 05:58 PM
Post #9


HR 9
Group Icon

Group: Moderator
Posts: 4,356
Joined: 13-August 03
User's local time:
Feb 9 2010, 06:14 PM
From: Blackpool UK
Member No.: 492



Well, yes and no, because the redirect will only occur when bRedirect = true and bRedirect will only be true if the hostname as requested does not contain "www"

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

so as MainDomain is already www.domain.com and is then concatenated with pathinfo the second HTTPrequest (on redirect) will be to www.domain.com and hostname will have www in it, therefore no redirect.

the only thing I miss out is explicitly setting bRedirect to false but as it will be false by default it's a couple of clock cycles saved.
Go to the top of the page
 
+Quote Post
Shane
post Jan 13 2005, 09:53 AM
Post #10


HR 6
******

Group: Active Members
Posts: 850
Joined: 4-May 04
User's local time:
Feb 9 2010, 02:14 PM
From: Atlanta, GA
Member No.: 3,454



If you don't set bRedirect to true in the instr() block, http://www.mydomain.com/index.aspx wouldn't get 301'd, so you miss 2 of his 4 cases.
Go to the top of the page
 
+Quote Post
Raphael
post Jan 13 2005, 09:56 AM
Post #11


The Limey Cowboy
******

Group: Active Members
Posts: 722
Joined: 17-December 04
User's local time:
Feb 9 2010, 02:14 PM
From: New England
Member No.: 5,984



QUOTE(chrishirst @ Jan 12 2005, 02:53 PM)
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).
*

I'm so glad I use Apache exclusively.
Go to the top of the page
 
+Quote Post
chrishirst
post Jan 21 2005, 07:07 PM
Post #12


HR 9
Group Icon

Group: Moderator
Posts: 4,356
Joined: 13-August 03
User's local time:
Feb 9 2010, 06:14 PM
From: Blackpool UK
Member No.: 492



Ok thought I'd posted this but obviously not. (IMG:http://www.highrankings.com/forum/style_emoticons/default/biggrin.gif)

the two variables hostname and pagename are pulled from two disconnected checks, hostname is the requested URI.
pathname is the URI that is returned by the server in response to the request and will always end with the default doc name should this be the root or a folder name.

so what the script does is strip the default doc name from the returned URI NOT the requested URI. The resultant pathinfo (minus the default doc name) is then concatenated to the domain name (MainDomain) so the redirected request will never have the default doc name in it. The fact that pathname will again return the default doc and strip it out does not matter. it is simply there to tell the useragent NOT to use the default doc name with any reference to this URI when the redirect is triggered.

So to redirect if the request includes a default doc name (which is missing from my script) an extra line should be added
CODE
if left(hostname,instr(hostname,".")) <> "www." then bRedirect = true
'  new line to be inserted
if instr(lcase(hostname),"default.asp") > 0 or instr(lcase(hostname),"index.asp") > 0 or instr(lcase(hostname),"index.aspx") > 0 then bRedirect = true
' existing code
if bRedirect then


This still cannot cause a locked loop as the second request will not meet the if criteria (no default doc name in hostname) the only time a locked loop could occur is by checking if pathname has a default doc name because this could always return true.
Go to the top of the page
 
+Quote Post
MCP
post Feb 20 2006, 09:19 AM
Post #13


AKA Arizona Web, SearchStudent, and Chris Hooley
****

Group: Active Members
Posts: 280
Joined: 3-September 03
User's local time:
Feb 9 2010, 02:14 PM
From: Phoenix Arizona
Member No.: 721



chrishirst, do you have this script running on any of your sites? This looks like a very helpful alternative to ISAPI filters. Thanks for the code snip!
Go to the top of the page
 
+Quote Post
jehochman
post Jul 24 2006, 03:07 PM
Post #14


Jonathan Hochman
Group Icon

Group: Moderator
Posts: 1,554
Joined: 27-November 05
User's local time:
Feb 9 2010, 02:14 PM
From: Connecticut - Land of Steady Habits
Member No.: 9,569



For doing page level 301 redirects in IIS with non-ASP pages (e.g. hosting provider doesn't want to ASP process .HTM pages because of the possibility of script injection attacks), does anybody have a more elegant solution than ISAPI_rewrite?

...sorry for the heavy technobabbly.
Go to the top of the page
 
+Quote Post
mcanerin
post Jul 24 2006, 11:52 PM
Post #15


HR 7
Group Icon

Group: Moderator
Posts: 2,241
Joined: 31-July 03
User's local time:
Feb 9 2010, 11:14 AM
From: Calgary, Alberta, Canada
Member No.: 170



Does this help?:

http://www.mcanerin.com/EN/articles/301-redirect-IIS.asp

It's even got pretty pictures and a how-to (IMG:http://www.highrankings.com/forum/style_emoticons/default/wink.gif)

Also, Chris, could you do me a favour and double check the code on this page?

http://www.mcanerin.com/EN/articles/301-re...t-scripting.asp

Because I think yours looks better (IMG:http://www.highrankings.com/forum/style_emoticons/default/smile.gif) If it is, I'd like to reprint it, if I may - what link/anchor text do you want for attribution/thanks/kudos?

Ian
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >   
Fast ReplyReply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



This forum is sponsored by High Rankings, a Boston SEO Agency
- Lo-Fi Version Time is now: 9th February 2010 - 01:14 PM