Everest Computers Blog About Computers and Web Design

Google and other search engines generally don’t like when the link on a website leads to nowhere i.e. the link is broken. This is why many websites publish external links through a forwarding page, which uses redirection techique to open the requested page. The forwarding page is a wrapper that firstly checks if the requested site or the page exists on this site and only then takes a user to this website.

I’ve created a very simple forwarding page, which is shown below. It is written using ASP – my favourite dynamic web page technology – but can easily be adapted for PHP and JSP.

This is how the forwarding page redirects the request (see the page’s code below this explanation):

  • Initialise some variables and obtain the value of the url a user will be send to.
  • Check if url contains “http” in front. If it doesn’t, add it.
  • Create XMLHTTP object and try to get response from the url using GET command. The response may be different for http://url.com and http://www.url.com, this is why we need to try both combinations before giving up.
  • If response code is 200, the page was found and everything is fine, so go on and do forwarding by calling Response.Redirect().
  • If response code is not 200, for some reason the page cannot be found, so show this page with the returned code.

<%@ Language=VBScript %>
<%
dim pg
dim status
pg = Request.QueryString("p")
status=""

if (pg<>"") then
    if (mid(pg,1,7)<>"http://") then
	pg="http://" & pg
    end if 

    on error resume next

    Dim objXMLHTTP
    Set objXMLHTTP =
	Server.CreateObject("Microsoft.XMLHTTP")

    dim a
    a=0
    do while (a<=2)
	objXMLHTTP.Open "GET", pg, False
	objXMLHTTP.Send
	status = objXMLHTTP.Status
	if (status=0) then
		if (mid(pg,1,11)="http://www.") then
			pg = "http://" & mid(pg,12)
		else
			'Assuming http:// is in front
			pg = "http://www." & mid(pg,8)
		end if
		a=a+1 'Try one more time
	else
		a=3 'Exit
	end if
    loop

    if (status=200) then
	response.redirect(pg)
    else
	'status="error!", show this page
    end if

    Set objXMLHTTP=Nothing
end if
%>

<HTML>
<BODY>
<P>Could not forward to the resource <%=pg %>.</P>
<P>The page you were trying to access has returned
    the following status: <%=status %>.</P>
</BODY>
</HTML>

 

38 Responses to “External link through a forwarding page with Response.Redirect”

  1. work online

    Hi there;

    I finally got my page not found 404 error working.

    Is this something like a 404 error??

  2. George

    @Jake:
    No, forwarding has got nothing to do with 404 error message redirect. Maybe this article will help you with 404 error redirect: Wordpress permalinks on IIS6 for subdirectory blog location.

  3. Enzyte

    Your code is really helpful for me. Thanks alot!

  4. Mustang Ford

    Thanks for his post! Was very helpful for me!

  5. ival

    I must say that this is a very good post. How do you addapt this to PHP, do you have a step by step process?

  6. George

    @Ival: To be honest, I don’t know how to re-write the above code in PHP, that’s why I wrote it in ASP. But I wouldn’t think it would be difficult. If I have time later this month, I’ll come back to it and try to add the PHP solution.

  7. Nicky

    Cool, Thanks! N

  8. How to start a nursing agency

    I appreciate the fact that you are letting us see the previews

  9. web development

    Redirection technique, it’s really great! Thanks for sharing code, it is really useful.

  10. online shopping

    do follow is the best way to go we can help each other out

  11. sagar

    great tip man. i think folow each other is a best method. what do u say..

  12. Adam Railing

    Thank you very much for the code. A real big help.

  13. Provo Used Car

    Thanks for the run down. I have an 18 page website with over 100 links and I’m still filtering it to make sure I don’t have any broken links. This has helped.

  14. Computer Hard Disk Data Recovery

    This is very nice and usefull tip, thanks!

  15. komikya

    i like it.))

  16. dhanti

    Thanks, This help me,

  17. Propert for sale

    nice blog

    keep updated

  18. Lig tv izle

    i like it.))

  19. John

    I just wonder though, I think even the one you are running now would make your blog not really count as dofollow since there isn’t a direct link to the page.

  20. Earth4Energy

    A really great post here. I assume there’s a chance to post more about related theme here. Really great. Thank you.

  21. Web Design Dubai

    Hi,
    its very nice post.
    Thanks
    keep sharing

  22. currency trading forex

    The code was great, really helped me out. Thanks for the great post.

  23. web design portsmouth

    Have not used VBScript in a while. Will check this out. My ASP needs work. Thanks.

  24. Hectic Capiznon Bloggers 2009

    I must say that this is a very good post. it is very useful information. I really recommend this post must read by everybody. :)

  25. donate a car

    Great tips….its d best way to each other

  26. last ned filmer

    wow, this information was just what I needed right now, I had a problem regarding to this.. Thanks to this post, it is solved:D

  27. collocation

    Great code, really helpful.

  28. bee media

    thanks for sharing this information I like it and I gain some knowledge about your topic..

    thanks you very much,,

  29. The Film Wall

    Thanks for this post.i want to need it.really useful this codind.i will trying this coding to redirecting….thanks

  30. web tasarim

    great tip man. i think folow each other is a best method. what do u say..

  31. Digital SLR

    Finally I got what I was looking for.

  32. Michele

    I enjoyed reading your article, thanks for the information. Michele

  33. web designer mom

    that’s a great tip and a very interesting read. im going to come back to read more of these.

  34. Free css templates

    Really awesome blog. I enjoyed reading this review from you. I found that you really update your site regularly that made me more interesting. I’ve bookmarked your site for my future use.

    Thank you
    sagar

  35. lancashire

    Great tips checking weather the pages you are linking to can be a pain this definately solves that thanks .

  36. credit counseling services

    Love the code, save me. Great job.

  37. number man

    This is an extremely helpful blog and this post is wat I’ve been searching for.

  38. Cheap Neckties

    great redirection techique.thanks man

    Regards,
    Ravi Verma

 
Powered by WordPress |  Admin
Copyright © 2007 - 2009 Everest Computers: Computer Support & Web Design. All rights reserved.