1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Rewrite - force non www and https?

Discussion in 'Server Configuration and Hosting' started by Smooth, Jan 29, 2016.

  1. Smooth

    Smooth Active Member

    Hi,

    Quick one that has been making my head hurt and me to break things over and over.

    Standard apache htaccess:

    Code:
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://domainname.com/$1 [R,L]
    Is working well for forcing https, but how is that amended to force non www?

    Thanks!
     
  2. Steve F

    Steve F Well-Known Member

  3. Smooth

    Smooth Active Member

    Thanks @Steve F but Im not sure how to integrate the two?

    i.e. this doesn't seem to work:

    Code:
    RewriteCond %{HTTP_HOST} www.example.com$
    RewriteRule ^(.*)$ https://example.com$1 [R=301,L]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://domainname.com/$1 [R,L]
    
     
    Last edited: Jan 29, 2016
  4. Steve F

    Steve F Well-Known Member

    That looks ok, just replace the domain names with your own of course. :)
     
    Smooth likes this.
  5. Smooth

    Smooth Active Member

    Thanks @Steve F! Was just missing one '/' on line 2:

    Code:
    RewriteCond %{HTTP_HOST} www.example.com$
    RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://domainname.com/$1 [R,L]
    I really appreciate your help - cheers (y)
     

Share This Page