codesnip

Redirecting a site hostname in Bitnami WordPress

Let’s say you have an Amazon EC2 Bitnami WordPress image, and you need to relocate your url to a new hostname, whether it be for rebranding or simplification.

You can force your URL to instantly redirect to your new domain name.

In this example let’s assume:

  • The new domain name points to the same server your old one was. (for the example, we’ll call it jasonheckmanoldsite.com)
  • You only have one WordPress vhost on this install. (a standard bitnami WordPress app roll out)
  • You have already pointed your new DNS name to your A record (jasonheckmanoldsite.com and jasonheckmannewsite.com both point to the same instance)

To achieve this redirect, first you must access your SSH terminal and connect to your bitnami stack.

Once in, you should back up, then edit your bitnami wordpress config file.

#cp /opt/bitnami/apps/wordpress/conf/wordpress.conf /opt/bitnami/apps/wordpress/conf/wordpress.conf.bak

#nano /opt/bitnami/apps/wordpress/conf/wordpress.conf

Add the following lines somewhere before the <directory> tag

#New URL redirection
<If "%{HTTP_HOST} != 'www.jasonheckmannewsite.com'">
        Redirect / http://www.jasonheckmannewsite.com/

Remember to update the www.jasonheckmannewsite.com fields to match your desired new hostname.

What this snippet does is fairly simple. IF the http host does not equal ‘www.jasonheckmannewsite.com’ change it to that.

Once you’ve saved your changes. You need to restart apache.

#sudo /opt/bitnami/ctlscript.sh restart apache

For best performance, you should also update your WordPress configuration to point to the new hostname in the WordPress url and site url (set in settings/general).

Don’t forget to save your server some work by also updating all of the URLs throughout your content.

I prefer using the Velvet Blues Update URLs plugin for WordPress.
Thanks, good luck!