web analytics

Permanent redirect from non-www to www a Ghost blog with Apache

A domain with www and without www will be recognized as a different URL by search engines. In addition, most people will type in the blog URL without the www automatically on their browser, it’s a habit, right?. If you don’t set it up, then when the visitors opened your blog without www, they will see the “page not found”.

To redirect from the non-www domain to the www a Ghost blog, you can use Apache. You can redirect it permanently.

I’m using Ubuntu and here is my config.
I created two VirtualHost in sites-avaiable directory.

For non-www:


ServerName tfq.me
Redirect permanent / http://www.tfq.me/

And for www domain:

ServerName www.tfq.me
ProxyPass /
ProxyPassReverse /
ProxyPreserveHost On
RewriteEngine On
RewriteOptions inherit

The URL in config.js for Ghost is using www.
Don’t forget to reload your Apache service.

Note:
I’m using port 8080 because I also running Varnish and my Ghost blog is running on port 2370 because the default port is used for another Ghost blog.