mod_rewrite rule to redirect root separate from everything else

Took me a bit to get this working and maybe someone else will find this useful.

In our case we have a on-premise service being moved to the cloud. To prevent an outage and not break any links for the first month or so after the migration a new domain has been chosen to.

Example URLs:

    • This should forward to the root of the new service (
    • This should redirect to the specified location on the old service (

Right now DNS looks like this:

  • ->
  • ->
  • ->

Because¬† is vendor maintained we didn’t want to goof with it to much or we’d just put the rewrite rules on it and save us having to use a third server (

Our solution was:

  1. Created a new DNS alias called and pointed it at (
  2. Alter the Apache vhost configuration on so it would respond to
  3. Configured the following re-write rules on
  4. On migration day we changed to point to (

Not overly complicated but it took me a while to figure out how to get the rewrite rules working properly.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.