How I redirected the web traffic for my old domain to the new one

I recently decided to change the domain name of my personal website from to because it is shorter and easier to remember. I don’t want visitors of to receive a 404 Not Found or any other error so I redirected all the traffic to In this article I’ll be sharing the steps I took to accomplish this.

Launching a server for my old domain

To assign a server to my old domain, I launched a new instance of an Ubuntu Server then configured the DNS A records of which was hosted at GoDaddy to point to the server’s external IP address. This article will not cover how I configured my DNS records to point to my server since every registrar provides a unique way of changing their DNS records. You must already have knowledge on how to configure the DNS with your registrar.

Setting up virtual hosts with Apache

Next I created a virtual host for using the same steps from a guide I recently wrote.

Redirecting traffic to the new domain

I configured the virtual host for to redirect to by editing /etc/apache2/sites-available/

sudo vim /etc/apache2/sites-available/emmanuelcorrales.conf

to look like this

<VirtualHost *:80>
    DocumentRoot /var/www/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    RedirectMatch permanent ^/(.*)$$1

The important part to note here is the line with the RedirectMatch. This line is the configuration I need to redirect traffic from to

I restarted the Apache web server to apply the changes I’ve made to the configuration.

sudo service apache2 restart

After restarting, visiting will redirect me to

Enabling HTTPS for Apache

At this point HTTPS request is still not supported and visiting causes an error on my browser. To support HTTPS request I configured Apache to enable SSL for my old domain by running the following commands:

sudo a2enmod ssl
sudo a2ensite default-ssl.conf
sudo service apache2 restart

After that I was able to access through my browser. However, the browser warns me that my connection is not private because I have an invalid certificate. To remove this, I needed to install a certificate issued by a trusted Certificate Authority but unfortunately I don’t want to buy one so I installed the free certificate provided by Let’s Encrypt.

Installing Let’s Encrypt SSL Self Signed Certificate for Apache

I cloned the repo of Let’s Encrypt to a directory on my server using Git.

sudo apt-get -y install git
cd /usr/local
sudo git clone

Then I generated an SSL certifacte for my old domain by running the following commands below and entering all the required credentials.

cd /usr/local/letsencrypt
sudo ./letsencrypt-auto --apache -d

After this the certificate was installed at /etc/letsencrypt/live and I confirmed the status of my SSL certificate by visiting the link below.

And that’s it. I have successfully redirected all urls from my old domain to the new one. If you know a better way to do this please don’t hesitate to approach me.