/ Technology

How to redirect www to non-www in Ghost

After basic configuration, I wanted to redirect my www domain to non-www.  I couldn't find any tutorial to do this, so I figure out by myself. I'm using Digital Ocean (if you want to use it, with this referral link you'll receive 10€) to configure everything with Ghost one click app.

Setting SSL in both domains with Let's Encrypt

  • Log in to your server through SSH.
  • Change user to ghost user sudo -i -u ghost-mgr.
  • Go to cd /var/www/ghost.
  • Follow these two steps with each domain (www and non-www).
    • Config url ghost config url https://www.yourdomain.com.
    • Setup SSL ghost setup nginx ssl.

It's time to check if you have your SSL working in both domains. Everything okay? Keep reading!

Adding redirections

  • Go to cd /var/www/ghost/system/files.
  • Open your config files www.yourdomain.com-ssl.conf and www.yourdomain.com.conf and add at the end the following line return 301 https://yourdomain.com$request_uri;.
  • Restart Nginx sudo systemctl restart nginx.

With these simple steps, you'll have the redirection working properly. Hope this tutorial helps you. Have a nice day!