Reputation: 1155
I'm trying to force SSL on 3 pages of a website, and force the rest to http
mydomain.com/register , mydomain.com/checkout and mydomain.com/thanks all need to redirect to https: but any other page should just use http:
Is this possible?
I currently have some codeigniter specific stuff in my htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Upvotes: 1
Views: 938
Reputation: 1831
I think this code will work (specially for CodIgniter)
RewriteEngine on
# force HTTPS
RewriteCond %{HTTPS} =off
RewriteCond %{REQUEST_URI} (register|checkout|thanks)
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force HTTP
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !(register|checkout|thanks|css|img|js)
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [L]
Upvotes: 2
Reputation: 3345
Not a .htaccess solution, but here's how I force https connections:
// Redirect to secure port
if ($_SERVER['SERVER_PORT'] != 443)
{
$location = 'Location: https://www.blah.com';
header($location);
}
Hope this helps.
Upvotes: 2