4
votes

Hi currently i bought SSL Certificates from Godaddy and install in on LoadBalancer. I have an zend framework app, but i have the issues with site redirection to Https. Following are my Bootstrap code that i found easiest way to redirect my site to https :

 protected function _initForceSSL() {
     if($_SERVER['SERVER_PORT'] != '443') {
      header('Location: https://' . $_SERVER['HTTP_HOST'] . 
                $_SERVER['REQUEST_URI']);
      exit();
    }

Unfortunately server error is return. What am i missing here? Thanks

Update:

.htaccess at root of file

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ public/index.php [NC,L]
3
these type of redirects has to be done in .htaccess and not in your application code - Lenin Raj Rajasekaran
i tried few on .htaccess but still no effects, i update my question above to include my .htaccess. - d3bug3r
@emaillenin for my case where index.php are inside public folder? I am using Zend Framework - d3bug3r
$this->getRequest()->isSecure() should be used to check for secure transport. - Daniel W.

3 Answers

1
votes

Since you are using Zend Framework, you could try with the following code in your .htaccess file:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ public/index.php [NC,L]

Let me know if it works!

1
votes

Just add this function to your Bootstrap file:

protected function _initForceSSL() {
    if($_SERVER['SERVER_PORT'] != '443') {
        header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
        exit();
    }
}
0
votes

Following code is working for me.

 RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule .* index.php