Question

how to force www to naked url

I have the url mysite.com, everytime i press enter it redirects to www.mysite.com, I don’t want it to show the www part at all.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

@ariziragoran

You’ll want to make sure that you’ve setup a redirect for the www variant of your domain.

For example, if your domain is example.com, we’d use something such as:

server {
    listen 80;
    listen [::]:80;
    server_name www.example.com;

    return 301 https://$host$request_uri;
}

server {
    listen 80;
    listen [::]:80;
    server_name example.com;

    ....
    ....
    ....
    ....
}

The first server block handles the redirection from www to your base domain. The second server block is where you main configuration would be.