.htaccess - Apache www HTTPS Redirect -
i redirect traffic forms of url go https without www
i found code on post , works perfect https, adds www
rewriteengine on rewritecond %{https} off rewriterule .* https://www.example.com%{request_uri} [r=301,l] rewritecond %{http_host} !^www\. rewriterule .* https://www.%{http_host}%{request_uri} [r=301,l]
i tried removing www first rewriterule above, still redirects www
any ideas can change redirect go https without www
this happening 2 reasons.
in first set of rules, you're redirecting
www
, change this:rewriterule ^(.*)$ https://example.com%{request_uri} [r=301,l]
your second set of rules checking if
www
not on, , if isn't forcewww
. change rule following:rewritecond %{http_host} ^www\. rewriterule ^(.*)$ https://%{http_host}%{request_uri} [r=301,l]
so above checks see if www
on - if remove it.
you can combine these 2 rules instead of having them seperate:
rewritecond %{http_host} ^www\. [or] rewritecond %{https} !=on rewriterule ^(.*)$ https://%{http_host}%{request_uri} [r=301,l]
make sure clear cache before testing this.
Comments
Post a Comment