Force SSL on your PHP site

  • Last updated on: 2015-06-23
  • Authored by: Rackspace Support

To force SSL on your PHP site, you can use the following code in a .htaccess file:

#Force SSL on entire site
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://(YOURDOMAIN)/$1 [R,L]

#Force SSL on a specific directory
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^DIRNAME/(.*)$ https://YOURDOMAIN/DIRNAME/$1 [R,L]

Continue the conversation in the Rackspace Community.