error_page 418 = @nonwww; set $nonwww ""; if ( $http_host ~* "^www\.") { set $nonwww "${nonwww}0"; } if ( $nonwww ~* "^0+$" ) { return 418; } location @nonwww { rewrite ^ https://$tld$request_uri permanent; }