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>





March 13th, 2009 - 8:03 pm
Hi there;
I finally got my page not found 404 error working.
Is this something like a 404 error??
March 13th, 2009 - 10:03 pm
@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.
March 14th, 2009 - 3:34 pm
Your code is really helpful for me. Thanks alot!
March 16th, 2009 - 6:02 pm
Thanks for his post! Was very helpful for me!
March 17th, 2009 - 2:59 am
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?
March 17th, 2009 - 7:56 am
@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.
March 17th, 2009 - 8:30 am
Cool, Thanks! N
March 17th, 2009 - 3:00 pm
I appreciate the fact that you are letting us see the previews
March 17th, 2009 - 3:45 pm
Redirection technique, it’s really great! Thanks for sharing code, it is really useful.
March 18th, 2009 - 1:39 am
do follow is the best way to go we can help each other out
March 19th, 2009 - 1:28 am
great tip man. i think folow each other is a best method. what do u say..
March 19th, 2009 - 10:22 am
Thank you very much for the code. A real big help.
March 19th, 2009 - 2:50 pm
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.
March 19th, 2009 - 6:56 pm
This is very nice and usefull tip, thanks!
March 19th, 2009 - 9:52 pm
i like it.))
March 20th, 2009 - 2:17 am
Thanks, This help me,
March 20th, 2009 - 12:38 pm
nice blog
keep updated
March 20th, 2009 - 6:04 pm
i like it.))
March 21st, 2009 - 8:38 pm
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.
March 22nd, 2009 - 1:36 pm
A really great post here. I assume there’s a chance to post more about related theme here. Really great. Thank you.
March 23rd, 2009 - 8:09 am
Hi,
its very nice post.
Thanks
keep sharing
March 23rd, 2009 - 4:58 pm
The code was great, really helped me out. Thanks for the great post.
March 23rd, 2009 - 5:22 pm
Have not used VBScript in a while. Will check this out. My ASP needs work. Thanks.
March 24th, 2009 - 6:25 am
I must say that this is a very good post. it is very useful information. I really recommend this post must read by everybody.
March 24th, 2009 - 1:29 pm
Great tips….its d best way to each other
March 25th, 2009 - 12:16 am
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
March 25th, 2009 - 12:33 am
Great code, really helpful.
March 25th, 2009 - 8:49 am
thanks for sharing this information I like it and I gain some knowledge about your topic..
thanks you very much,,
March 25th, 2009 - 8:50 am
Thanks for this post.i want to need it.really useful this codind.i will trying this coding to redirecting….thanks
March 26th, 2009 - 2:24 pm
great tip man. i think folow each other is a best method. what do u say..
March 28th, 2009 - 10:24 am
Finally I got what I was looking for.
March 28th, 2009 - 5:38 pm
I enjoyed reading your article, thanks for the information. Michele
March 29th, 2009 - 3:17 am
that’s a great tip and a very interesting read. im going to come back to read more of these.
March 30th, 2009 - 3:35 pm
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
March 31st, 2009 - 9:56 am
Great tips checking weather the pages you are linking to can be a pain this definately solves that thanks .
March 31st, 2009 - 7:12 pm
Love the code, save me. Great job.
April 1st, 2009 - 3:40 pm
This is an extremely helpful blog and this post is wat I’ve been searching for.
April 1st, 2009 - 5:17 pm
great redirection techique.thanks man
Regards,
Ravi Verma