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

A domain with www and without www will recognized as 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 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 / http://127.0.0.1:2370/
ProxyPassReverse / http://127.0.0.1:2370/
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 my another Ghost blog.

Leave a Reply