Non-www to Www Nginx Redirect

Add this small block of code into your server{} block to redirect all non-www to the www version of your website.

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

Comments