.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.

  1. in first set of rules, you're redirecting www, change this:

    rewriterule ^(.*)$ https://example.com%{request_uri} [r=301,l] 
  2. your second set of rules checking if www not on, , if isn't force www. 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

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -