Redirect www to non-www

Hey team, I’m new to Ghost - sorry for questions :slight_smile:

Seems, I just installed Ghost on

But, there is no redirect from e.g. to non-www

I followed steps here Www to non-www on Digitalocean setup and here Solved: Need help on redirecting www. to non www. - GoDaddy Community

But, still doesn’t redirect…

Hi Andrii.

You need to make some changes in nginx to make this work. There are a few different ways.

The easiest (but not the cleanest) way I’ve found is to get into the command line:

ghost config url
ghost setup nginx ssl

This creates the necessary SSL certificates and Nginx files to handle redirecting properly.

Run ghost config url to reset the domain setting.

Then you need to edit the two new Nginx files that are created (you’ll see them printed in the console) starting with (one will have -ssl in the name and one won’t).

Within the server block add a new line (do the same in both files):

return 301$request_uri;

This will direct all traffic to your www domain, to your non-www domain.

Like I said, this may not be the cleanest way to do this but it’s the easiest I’ve discovered. Alternatively you could edit the existing Nginx files and create the SSL certificates from the command line. If anyone has any feedback on this, I’d love to hear it.