1

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]
Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
Martin Hunt
  • 1,135
  • 2
  • 14
  • 23
  • Probably duplicate - see for example these answers: http://stackoverflow.com/questions/4192948/remove-www-site-wide-force-https-on-certain-directories-and-http-on-the-rest – Marki555 Jul 11 '12 at 17:48
  • It is not duplicate, question is right. Need to find the solution for CodeIgniter.... For CI it is not working. – TechCare99 May 17 '14 at 05:46

2 Answers2

2

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.

SenorAmor
  • 3,351
  • 16
  • 27
  • If you are using apache, you should have access to many SSL-related variables, in PHP they will be visible under `$_SERVER[]`. Here is list http://www.modssl.org/docs/2.8/ssl_reference.html#ToC25 – Marki555 Jul 11 '12 at 17:50
2

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] 
TechCare99
  • 1,763
  • 6
  • 24
  • 33