Heal Your Church WebSite

Teaching, rebuking, correcting & training in righteous web design.

5 to ways permanently redirect an old church domain name to a new domain name

It is no sin for a church to change their domain name. However, it is an unspeakable Internet offense if you do not provide visitors – and search engines – with a quick, simple and painless redirect from the old domain to the new. Unfortunately not all church webmasters know even 1 way to avoid said sin, let alone 5; that is until now:

While I was surfing about for candidates on another topic, I came across the home page for the Vestavia Hills United Methodist Church of Birmingham, AL … or at least what I thought was the home page.

Actually, I’m thinking it was the old home page, or a home page whose sole purpose is to redirect visitors from vhumc.org to vestaviahillsumc.org – but does so in a way that gets in the way of seekers and search engines alike.

To that end, I’ve taken the time to demonstrate five different methods of implementing a search engine friendly, permanent redirect from the old domain name to the new – and in most cases, passing along any query string that may be the result of an old bookmark:

1. mod_rewrite (via .htaccess)
# The most preferred, but also at time the most difficult of approaches
# requiring you modify your .htaccess file as follows:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?vhumc.org$ [NC]
RewriteRule ^(.*)$ http://vestaviahillsumc.org/$1 [R=301,L]
2. Perl:
#!/usr/bin/perl -w
# some might argue that this is the most difficult method, and
# I might tend to agree as a n00b might find out that they should NOT
# delete the blank spaces and line feeds in between the quote {} tags.
use strict;
my $q = ($ENV{'QUERY_STRING'}) ? "?".$ENV{'QUERY_STRING'} : "";
print qq{Status: 301 Moved Permanantly
Location: http://www.vestaviahillsumc.org/$q\n\n};
3. ASP classic
' # yes, I know we live in the age of .NET, but if you note, today's subject
' # is redirecting to an .asp kinda host, so it could be the same for their
' # old domain.
< %@ Language=VBScript %>
< %
qs = ""
if(Request.QueryString.Count > 0) qs = "?" & Request.QueryString
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://vestaviahillsumc.org/" & qs
4. PHP
< ?php
// # perhaps the easiest and most reliable solution for most of you out there
// get querystring - if it exists
$q = empty($_SERVER['QUERY_STRING']) ? "" : "?".$_SERVER['QUERY_STRING'];
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://vestaviahillsumc.org/".$q);
5. JavaScript
<script type="text/javascript">
# I don't prefer this method as most search engines won't get it, still
# it is sometimes the only solution a limited webmaster can muster on
# a limited budget and hosting situation.
# Also note we don't merely assign a value to href, there is a good reason
# for this explained here:
# http://andylangton.co.uk/articles/javascript/javascript-redirect-scripts/
var qs = window.top.location.search.substring(1);
qs= (isEmpty(qs) ? "" : "?" + qs);/* capture query string */
location.replace('http://www.vestaviahillsumc.org/' + qs);

As you can see, there’s more than one way to skin the old redirect cat. Of course there is also more than one way to foul this all up, which is why I’m providing you with a list of additional reading references just in case you find you’ve caused irreparable harm to your website and reputation the above examples as is (note, you’ve just been warned with my disclaimer):

That said, if you’re still pondering which method to employ, here are my rules of thumb regarding which redirect method to use in which order:

  1. If you have shell access and the know-how:
    .htaccess (mod_rewrite)
  2. If you can’t do it .htaccess
  3. if you can’t do it PHP
  4. if you can’t do it Perl
  5. if you can’t do it Javascript
    meta tag
  6. if you can’t do the meta tag
    hire some help

Oh and for those of you who note that I didn’t include a “how to redirect using the refresh meta tag” – it’s because one of the objectives in this exercise is to redirect to preserve search engine visibility and ranking. The unfortunate abuse by spammers of the taggery means potentially hiding your lamp beneath a basket due to no fault of your own.

For more information on how to modify the .htaccess file to redirect domains can be found here:

Still interested in reading more on the topic of redirecting from old domains to new domains? Want to see where I got and/or vetted some of my solutions?


  1. In the Perl example, the comments need to come after the shebang line.

    Ditto the PHP example.

  2. Yeah, I know – they were originally my personal notes, then I threw them into the exmaples …

    … then the stinking WordPress editor is hosing them when I go that way …

    … lemme go directly into MySQL and hammer it out that way.

  3. It’s probably also worth mentioning that on the JavaScript redirect page, you should also put some text saying that you have moved and what the new URL is, for those people who have NoScript installed etc.

  4. Pingback: links for 2007-08-28 « geek notes

  5. >It is no sin for a church to change their domain name

    Thanks for clearing that up. Ha ha 🙂