Rewrite - force non www and https?

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!
 
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:
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)
 
Top Bottom