Advertisement
Russell

Forcing HTTPS with .HTaccess

Dec 14th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. To force all web traffic to use HTTPS:
  2.  
  3. RewriteEngine On
  4. RewriteCond %{SERVER_PORT} 80
  5. RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
  6.  
  7. RewriteEngine On
  8. RewriteCond %{HTTPS} !=on
  9. RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  10.  
  11. To force a specific domain to use HTTPS:
  12.  
  13. RewriteEngine On
  14. RewriteCond %{HTTP_HOST} ^example\.com [NC]
  15. RewriteCond %{SERVER_PORT} 80
  16. RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
  17.  
  18. To force SSL on a specific directory:
  19.  
  20. RewriteEngine On
  21. RewriteCond %{SERVER_PORT} 80
  22. RewriteCond %{REQUEST_URI} directory_name
  23. RewriteRule ^(.*)$ https://www.example.com/directory_name/$1 [R,L]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement