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!



Photo
- - - - -

Another Redirection Issue


  • Please log in to reply
42 replies to this topic

#16 Pacerfan

Pacerfan

    HR 1

  • Members
  • Pip
  • 5 posts

Posted 12 September 2006 - 03:25 PM

Hi Chrishirst,

We are finally ready to rollout our new site on Monday. I have a couple of additional questions regarding this topic if you don't mind.

1. How long (rough estimate) will we need to leave the server.transfer solution in place if we go that route?

2. If we decide to go with the 301 redirect (still using the code sample you provided with the array), any idea on the length of time (rough estimate) it would take Google to index our new .aspx files?

Thanks again for all of your help. I really appreciate it!

#17 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 6,447 posts
  • Location:Blackpool UK

Posted 12 September 2006 - 07:06 PM

1/ permanently

2/ a few weeks normally.

#18 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 6,447 posts
  • Location:Blackpool UK

Posted 02 March 2007 - 06:33 AM

Rectified the code after some bugs found
See http://www.tek-tips....d...1205&page=1 for the issues raised.
Redirect 2000 (ver 2.54) has been replaced with Redirect XP see below
CODE
Code eaten by the bugs

Edited by chrishirst, 06 March 2007 - 07:10 PM.


#19 kblm

kblm

    HR 2

  • Members
  • PipPip
  • 13 posts

Posted 06 March 2007 - 12:14 PM

Chris, couple of things,

1) Looks like you have a typo on this line:
if instr(request.servervariables("QUERY_STRING"), pageArray(i,0)) > 0 then

The (i,0) should be (0,i)......I noticed your posting on the other message board was correct......man, I couldn't for the life of me figure out why I pasted that one and it worked, and this one and it didn't....so I compared the two and found that.

2) Any way to get the server response for the 301 to not include the :80 in the address?

3) As for #2, does the server port matter when it comes to 301 redirects and SEO?

4) Lastly, I'm assuming that if I want to 301 redirect a user from a specific page, to the root of the site (because I don't want them to go to the default page in the url), I can use the following:

pageArray(0,0) = "badpage.php"
pageArray(0,1) = " "

Using a space for the page to send them to....essentially taking them to the root of the site. I tried no space and a / but neither worked.


Awesome script.....I know we can always count on you to solve those complex ASP problems!

-Kevin

#20 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 6,447 posts
  • Location:Blackpool UK

Posted 06 March 2007 - 04:44 PM

QUOTE
Looks like you have a typo on this line:
doesn't surprise me, at one point I had 4 different bits of code on the go, I've corrected it now here as well.

If the port number is included use a replace(newURI,":80","") to strip it out.

the port number will only matter if you are using a non-standard port for the HTTP server otherwise 80 is the default

A space should be perfectly ok and a empty string ("") should as well, using a "/" will result in www.domain.tld// which may result in the server trying to redirect to a folder with no name (theoretically)

#21 kblm

kblm

    HR 2

  • Members
  • PipPip
  • 13 posts

Posted 06 March 2007 - 05:19 PM

QUOTE(chrishirst @ Mar 6 2007, 04:44 PM) View Post
doesn't surprise me, at one point I had 4 different bits of code on the go, I've corrected it now here as well.

If the port number is included use a replace(newURI,":80","") to strip it out.

the port number will only matter if you are using a non-standard port for the HTTP server otherwise 80 is the default

A space should be perfectly ok and a empty string ("") should as well, using a "/" will result in www.domain.tld// which may result in the server trying to redirect to a folder with no name (theoretically)



I added:

newURI = replace(newURI,":80","")

That works perfectly to remove the :80

The server is running on port 80, I just wasn't sure how Google and the other SE's would see the 301 to a url with the :80 in it.

As for the empty string (""), it works ONLY when it matches one of the pages in the array. The script doesn't work for serving the general 404 error page if you use an empty string. The only thing that works both ways is the space (" ").

-Kevin

#22 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 6,447 posts
  • Location:Blackpool UK

Posted 06 March 2007 - 07:06 PM

Ok retested the code because this
QUOTE
As for the empty string (""), it works ONLY when it matches one of the pages in the array. The script doesn't work for serving the general 404 error page if you use an empty string. The only thing that works both ways is the space (" ").
shouldn't happen because no array match should drop through to the ... else thus displaying the error page and return the 404 response to the User Agent.

It transpires in VbScript that when you run an instr() comparison against a empty variable it returns a value of 1 rather than 0 which would be expected. So the script returns bFound as True even though there is no match.


so Redirect XP (Ver 3.21) is below
CODE
<%
dim i, newURI, req, pageArray(1,50)

pageArray(0,0) = "/dir/pagename.htm"
pageArray(1,0) = "/dir/pagename.asp"

bFound = false

for i = 0 to ubound(pageArray,2)
if pagearray(0,i) <> "" then          
    if instr(request.servervariables("QUERY_STRING"), pageArray(0,i)) <> 0 then
        req = replace(request.servervariables("QUERY_STRING"),"404;","")
          newURI = replace(req,pageArray(0,i), pageArray(1,i))
           bFound = true
     end if
end if
if bFound then exit for

next

if bFound then
' uncomment the next line to keep the original URI but show the new content
'server.transfer("/newdir/" & pageArray(1,i))
'server.transfer(pageArray(1,i))
' uncomment the next lines to redirect to the new pagename
   response.status = "301 Moved Permanently"
   response.addheader "Location", newURI
   response.end()
else
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Not Found</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
This is the 404 page
<body>
</body>
</html>

<%
   response.status = "404 Not Found"
   response.end
end if
%>
Test to destruction to see if I have still missed something.

To answer the point about having :80 in the URL
Technically it would make no difference to accessing the site , however it would be a different URL to search engines so would create the same issues as having default.asp in the URLs or the www vs non-www issues.

#23 kblm

kblm

    HR 2

  • Members
  • PipPip
  • 13 posts

Posted 06 March 2007 - 07:30 PM

Chris, I don't know VB that well.....can you explain this section:

pageArray(0,0) = "/dir/pagename.htm"
pageArray(1,0) = "/dir/pagename.asp"


I was under the impression that the first line is the page you are checking, and the second is the page you are 301'ing to.

1) Can you add more pages to go to different 301'd pages?
2) In your previous script, the 2nd line the array was (0,1), and now it's (1,0)....why?

Thanks for taking the time to troubleshoot this.....you've been a huge help!

-Kevin

#24 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 6,447 posts
  • Location:Blackpool UK

Posted 06 March 2007 - 07:56 PM

QUOTE
I was under the impression that the first line is the page you are checking, and the second is the page you are 301'ing to.
That,s correct
to continue the array would be
pageArray(0,0) = "/dir/pagename.htm"
pageArray(1,0) = "/dir/pagename.asp"
pageArray(0,1) = "/dir/anotherpage.htm"
pageArray(1,1) = "/dir/anotherpage.asp"

and so on

and for 2/ I have this script in a slightly different form for one site and pull the URIs from a database with a ADO GetRows() this creates the array dynamically , and I got the definitions opposite way around when I converted it to a static array.

It's one of the dumb things you do sometimes when you don't think about code anymore and just type it from memory. mf_type.gif mf_prop.gif nerd.gif


Offtopic

At least I don't do hexadecimal maths in my head anymore hmm.gif


#25 kblm

kblm

    HR 2

  • Members
  • PipPip
  • 13 posts

Posted 06 March 2007 - 09:07 PM

Chris......you rock. Thanks!

I'm assuming in VB that if you have this:

pageArray(0,0) = "oldpage.php"

and nothing else, it assumes that the second part of the array (1,0) is an empty string, therefore, it will take you to the root?

Just checking.

It works great though, thank you so much.

-Kevin

#26 lastdonuk

lastdonuk

    HR 1

  • Members
  • Pip
  • 1 posts

Posted 07 March 2007 - 12:44 PM

Chris,

Thanks very much for this updated script - it's implemented and working very nicely now. As far as I know, this is the only(?) ASP solution to modifying site pages if you don't have full access to the IIS console (we're hosted on a shared environment).

Cheers,

Rob

#27 kblm

kblm

    HR 2

  • Members
  • PipPip
  • 13 posts

Posted 10 April 2007 - 06:09 PM

Chris,

I have a quick question on the array.

Is there any way to include a wildcard character in the array. For example, let's say I need to redirect the following pages:

testing_100.html
testing_101.html
testing_102.html

Basically any page that matches testing_*.html

And send them all to a single new page.

Is this possible without adding an entry for each page?

-Kevin

#28 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 6,447 posts
  • Location:Blackpool UK

Posted 11 April 2007 - 09:24 AM

it certainly can

simplest would be to use a regular expression,

function code
CODE
function ReplacePageName(strIn)
    dim objRE
    set objRE = New RegExp
    objRE.pattern = "\b(testing_).*?(\.html)"
    objRE.Global = True
    ReplacePageName = objRE.replace(strIn,"pagename.html")
    set objRE = nothing
end function



then after the "next" add
CODE
    if instr(request.servervariables("QUERY_STRING"), "testing_") <> 0 then
        req = replace(request.servervariables("QUERY_STRING"),"404;","")
          newURI = ReplacePageName(req)
           bFound = true
     end if

Edited by chrishirst, 11 April 2007 - 02:40 PM.
fixed the unbalanced paranthesis


#29 kblm

kblm

    HR 2

  • Members
  • PipPip
  • 13 posts

Posted 11 April 2007 - 12:44 PM

QUOTE(chrishirst @ Apr 11 2007, 10:24 AM) View Post
it certainly can

simplest would be to use a regular expression,


Chris,

I'm getting the following error:
CODE
Microsoft VBScript compilation  error '800a03f9'

Expected 'Then'

/error.asp, line 126

if instr(request.servervariables("QUERY_STRING"), "testing_")) <> 0 then
--------------------------------------------------------------^



Any ideas?

-Kevin

#30 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 6,447 posts
  • Location:Blackpool UK

Posted 11 April 2007 - 02:40 PM

unbalanced paranthesis is the problem biggrin.gif

there is an extra ")" that snuck in there






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

SPAM FREE FORUM!
 
If you are just registering to spam,
don't bother. You will be wasting your
time as your spam will never see the
light of day!