error_page 418 = @nonwww; set $nonwww ""; if ( $http_host ~* "^www\.") { set $nonwww "${nonwww}0"; } if ( $nonwww ~* "^0+$" ) { return 418; } # TODO: map need moved to conf.d map $host $tld { default $host; '~^www\.(?.*)$' $domain; } location @nonwww { rewrite ^ https://$tld$request_uri permanent; }