Gavin R. Putland,  BE PhD

Thursday, August 16, 2012 (Comment)

How to redirect Blogger pages to external URLs

Blogger™ has a facility called Custom Redirects (accessed via Settings > Search preferences) by which you can redirect a post or page to another post or page. But the destination must be within the same blog, and you are allowed only 10 redirections per blog.

Is there a way to redirect to an external page? Is there a way around the limit of 10 redirections? And can all this be done without resorting to JavaScript redirection (which is less search-engine-friendly)? Yes, yes, and yes — provided that the blog from which you are redirecting has a “layout” rather than an older “classic” template.

For the purpose of illustration, suppose you have a blog with three posts whose addresses (permalinks, URLs) are OldPostURL-A, OldPostURL-B, and OldPostURL-C, which you want to redirect to NewPostURL-A, NewPostURL-B, and NewPostURL-C, respectively, with a delay of 2 seconds. The new URLs may be inside or outside your blog.

Then you need to insert the following code in your template immediately after the <head> tag:

<b:if cond='data:blog.url == "OldPostURL-A"'>
<meta http-equiv="refresh" content="2; url=
NewPostURL-A" />
</b:if>

<b:if cond='data:blog.url == "
OldPostURL-B"'>
<meta http-equiv="refresh" content="2; url=
NewPostURL-B" />
</b:if>

<b:if cond='data:blog.url == "
OldPostURL-C"'>
<meta http-equiv="refresh" content="2; url=
NewPostURL-C" />
</b:if>

N.B.: This won't work if the blog from which you are redirecting uses a “classic” template. It seems that “classic” Blogger doesn't understand the “b:if” tag, with the result that the “cond” is always treated as true. Hence, if you try to use a series of conditional redirects in a “classic” template, the URL given in the last redirect will apply, and all posts on your blog will redirect to that URL. Yes, I write from experience! So you need to “upgrade” the template to a “layout”.

And yes, my experience also confirms that the redirection code must be inserted immediately after the <head> tag. Other code in between can stop the redirection code from working — even if you've made sure that the redirection code isn't inside a comment!

[Last modified January 6, 2015.]


Creative Commons License         Return to Contents
comments powered by Disqus