Advertisement
Guest User

.htaccess with cond if CF

a guest
Feb 11th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. What i'm looking for is the possibility to allow %{HTTP_HOST}%{REQUEST_URI} redirect to https://%{HTTP_HOST}%{REQUEST_URI} all the time.
  2. And take into account if a Proxy (CloudFlare) is making the request to always use HTTPS. Removing the redirection loop.
  3. I want to be able to have CF on and off and for both options to work.
  4.  
  5. domain -> https://www.domain if from CF then add the proper rule.
  6.  
  7. RewriteCond %{HTTP} on
  8. RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  9. RewriteCond %{HTTP_HOST} !^www\.
  10. RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  11. RewriteCond %{HTTP:X-Forwarded-Proto} =http
  12. RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  13. RewriteCond %{HTTP_HOST} !^www\.
  14. RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  15.  
  16. This works to forward everything to WWW but is not taking into account a HTTPS request is available.
  17. If i enable CF everything is forwarded fine to https://www.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement