views:

56

answers:

2

I've got a site built on top of Kohana 2.3 which I now have to make all links https.

I set this in application/config/config.php.

$config['site_protocol'] = 'https';

This makes all links on the site use the https protocol.

Except, when I first enter the site via http, it will not automatically forward to https.

Is there a way to make Kohana do this, or do I just need to do some custom coding?

I've found this .htaccess rule too, will it be fine to just drop this in?

RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://yourdomain.tld%{REQUEST_URI} [NS,R,L]

Thanks.

A: 

I'm still interested in answers, but I solved this quickly with

if ( ! isset($_SERVER['HTTPS'])) {
    header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
    exit;
}

As Kohana bootstraps.

alex
A: 

Personally, and if possible, I'd do the redirecting with the web server. No sense hacking Kohana if you don't need to.

That said, I don't use Kohana so it may be doable.

I went straight to PHP because my .htaccess file covers a few domains, and I know PHP better than .htaccess rules (the example I found makes you specify the redirecting domain explicitly, I would need that to be automatic).
alex