Non-www to www redirect using Nginx

1 post / 0 new
#1 Wed, 05/09/2018 - 11:00
wfuk_stuart

Non-www to www redirect using Nginx

I've been trying to figure out how to setup a non-www to www domain redirect on a virtual host within Virtualmin with no luck.

The only way I've been able to get this to work is by manually editing the nginx config for the virtual host and using the following:

if ($host = 'tribaltracks.co.uk') {
    rewrite ^/(.*)$ http://www.tribaltracks.co.uk/$1 permanent;
}

Does anyone know how this can be achieved within Virtualmin or if there is a better way of doing this?

Many thanks.