• 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?

Smooth

Active member
#1
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!
 

Smooth

Active member
#3
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:

Smooth

Active member
#5
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)