Forcing www and https with CloudFlare and NearlyFreeSpeech in one 301 redirect (rather than two)

  1. Put this in .htaccess on NearlyFreeSpeech
    RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$$1 [R=301,L]
  1. On NearlyFreeSpeech, turn off canonical URLs and turn off force HTTPS. If either is forced on, requests to get redirected to and then to, regardless of settings in .htaccess.
  1. On CloudFlare, add the following page rule:
    URL: http://** Rule: Forwarding URL (Status Code: 301 - Permanent Redirect, Url:$2)
  1. Make sure enforce HTTPS is turned on in CloudFlare.
  1. You don't need any other rules because the .htaccess takes care of redirects from to

No comments:

Post a Comment