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:

  • https://onprem.pickysysadmin.ca
    • This should forward to the root of the new service (https://cloudservice.pickysysadmin.ca/)
  • https://onprem.pickysysadmin.ca/a_bunch_of_stuff/more_stuff
    • This should redirect to the specified location on the old service (https://onprem.pickysysadmin.ca/)

Right now DNS looks like this:

  • onprem.pickysysadmin.ca -> 10.0.0.1
  • cloudservice.pickysysadmin.ca -> 10.0.0.2
  • apache_redirect_server.pickysysadmin.ca -> 10.0.0.3

Because¬†onprem.pickysysadmin.ca 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 (apache_redirect_server.pickysysadmin.ca).

Our solution was:

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

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 *