0

I've tried several rewrite rules trying to make this work, but it would still redirect to https://www.*.
What I want to achieve is to redirect, www.sub.domain.com to https://sub.domain.com.

This is the code I tried:

RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^sub\.domain\.net$ [NC]
RewriteRule .? https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
GSerg
  • 76,472
  • 17
  • 159
  • 346

1 Answers1

0

Your rule doesn't work for two reasons

  • RewriteCond restricts the rule to requests for sub.domain.net and ignores requests for www.sub.domain.net
  • The RewriteRule uses %{HTTP_HOST} in the substitution. So even if it would apply for www.sub.domain.net, it would just redirect it to www.sub.domain.net again.

So your rule should rather look like

RewriteCond %{HTTP_HOST} ^www\.sub\.domain\.net$ [NC]
RewriteRule ^ https://sub.domain.net%{REQUEST_URI} [R,L]

When everything works as it should, you may replace R with R=301. Never test with R=301.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198