http redirect https nginx ispconfig3

Discussion in 'ISPConfig 3 Priority Support' started by S0ft, Mar 18, 2015.

  1. S0ft

    S0ft Member HowtoForge Supporter

    I have now tried this
    Code:
    if ($http_host != "domain.tld") { rewrite ^(?!/\b(stats|error)\b)/(.*)$ https://domain.tld/$2 redirect; }
    
    It only works if you go from http://domain.tld to http://www.domain.tld
    but it doesn't work if you want http://domain.tld to https://domain.tld

    so tirelessly looking I found this code that ran on the nginx directives

    Code:
    ssl on;
    error_page 497 https://$host$request_uri;
    
    only works with a dedicated IP.

    by now
    works very well
    is this the right path?
     
    Last edited: Mar 18, 2015
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    I use this redirect:

    Code:
    if ($scheme != "https") {
              rewrite ^ https://www.howtoforge.com$request_uri? permanent;
            }
     
    S0ft likes this.
  3. S0ft

    S0ft Member HowtoForge Supporter

    it works
     
    Last edited: Mar 18, 2015
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    A site should never be available on domain.tld and www.domain.tld as thats bad for your search engine rank (duplicate content). So you should decide if your site shall be with or without www and then use my rewrite rule and just replace:

    https://www.howtoforge.com

    with your domain (either with www or without).
     
  5. S0ft

    S0ft Member HowtoForge Supporter

    rectifying the above, also works without www
    till thanks
     

Share This Page