Redirecting WWW to NON-WWW (Nginx only)

Redirecting WWW to NON-WWW is very important for SEO and I miss it a lot as a default option in HestiaCP.

I know it can be done implementing this, but since I already redirected HTTP to HTTPS from that check option when I added my website, now I don’t know what the exact file I need to go, and what block I should edit, should it be better to add a new block instead for better performance or edit the existed block. There are many of them in these files which made me confused! :frowning:


Hope someone can tell me how to do it.

You need to create a new template from two files (tpl and stpl) in the directory:

Add this entry in the * .stpl file in the server section:

if ($host ~* www.(.)) {
set $host_without_www $1;
rewrite ^(.
)$ https://$host_without_www$1 permanent;

Then open the domain editing in the HestiaCP panel and select the created template.

1 Like

Thanks, Dmitry! But that didn’t work for me, I ended up with that black page error! Not sure if this is related but I didn’t install Apache, I’m just using Nginx instead.

By the way, should nonwww.tpl I’ve created be empty and only put the snippet you gave in the stpl version?

The above code was copied incorrectly for me and cannot be edited. Try to take this code on pastebin:

I am using Nginx + php-fpm.

The tpl and stpl files should be roughly similar to each other.
I can show my template for wordpress as an example:
wordpress2.tpl -

wordpress2.stpl -

This template redirects from http to https and www to non-www.

I’m not using WordPress in my business so I think this is not the right solution for me.

But thanks for trying to help me out, appreciate it.

I showed an example of implementing a redirect from www to non-www in HestiaCP templates. I hope this helps you create your own template for your needs.

so I have solved it, redirected with 301

www to non-www

non-www to www

1 Like

Actually, I solved it without creating or editing any template file. Simply I did this:

nano /home/user/conf/web/

Adding this below server_name line:
if ($host != “”) { return 301$request_uri; }

systemctl restart nginx

Will break on next update…

You will have to edit the template you use… and preferable by creating a new template.

Oops! Didn’t know that. I’ll try creating a template and hope tuxuser template will work for me.

Thanks, dude! It works now perfectly.

You got a fat header which informs you about it in every config :grin:.

1 Like

A post was split to a new topic: Non www, www redirect