Non-www to www and vice versa

Discussion in 'Installation/Configuration' started by jaypabs, Jul 2, 2013.

  1. jaypabs

    jaypabs Member

    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;
    	}
    
     
  2. jaypabs

    jaypabs Member

    No one knows about this?
     
  3. falko

    falko Super Moderator Howtoforge Staff

    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;
    }
     
  4. jaypabs

    jaypabs Member

    Cheers!

    Thank you very much.
     
  5. Rafael Santana

    Rafael Santana New Member

    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.
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    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.
     

Share This Page