How can I rewrite nginx to redirect non-www to www and vice versa? I have tried the following by adding it in the nginx directives without luck. non-www to www: Code: server { server_name example.com; rewrite ^(.*) http://www.example.com$1 permanent; } www to non-www: Code: server { server_name www.example.com; rewrite ^(.*) http://example.com$1 permanent; }
www to non-www: Code: if ($http_host != "example.com") { rewrite ^ $scheme://example.com$request_uri? permanent; } non-www to www: Code: if ($http_host != "www.example.com") { rewrite ^ $scheme://www.example.com$request_uri? permanent; }
Even putting this code in [nginx directives], it continues appearing 2 urls. The strange thing is that in the url with www: the apache page appears and in the url without www the ispconfig page.
You respond here to an old and completely outdated post. Do not put any code into the nginx directives field, that's not required anymore. Remove your custom code and then just go to the redirect tab of the website in ISPConfig and select the seo redirect there that you want to use.