Redirect to https first then redirect non-www to www

Discussion in 'Installation/Configuration' started by mattltm, Sep 13, 2016.

  1. mattltm

    mattltm Member

    I'm trying to get a site ready for chrome's hsts preload list but i'm getting an error from the checking tool at

    The first issue is that I need to redirect all non-https to https followed by redirecting non-www to www subdomain. I can do it the otherway around (redirect non-www to www then send everything to https) but the preload tool wants it the other way around! I've tried a combination of using the redirects built into ISPConfig and other directives in the sites Apache Directives options but I just can't get it to work.

    Any help appreciated.
  2. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    Looking at the directives written to the vhost file, they are in the reverse order that you need, as you indicate - you'll have to use custom directives to change that for now, and probably add a a feature request to the issue tracker. It's untested, but you can probably leave the HTTP -> HTTPS redirect enabled, and just do the non-www -> www redirect in custom directives (or .htaccess file even).
  3. Ryan Rajpoot

    Ryan Rajpoot New Member

    I intended to redirect non-www to www and http to https. For that I have used below code and it's resolving perfectly. Please check whether code is correct or not.

    RewriteEngine On
    RewriteBase /
    #Redirect non-www to www

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    # Redirect to HTTPS
    RewriteCond %{HTTPS} off
    RewriteRule (.*) %{REQUEST_URI}

    Thank You.
  4. mattltm

    mattltm Member

    Thanks for the reply Ryan but your code is the wrong way around for what I needed. If you want to add your domain to chromes HSTS preload list then you must redirect to HTTPS first and then redirect non-www to www. This can be done as Jesse suggested above.
  5. Ryan Rajpoot

    Ryan Rajpoot New Member

    Thanks for the response, i will do as you said...

Share This Page