Friday, 21 August 2015

How to redirect http to https in Zend Framework

How to redirect http to https in Zend Framework

http to https, Follow the following:
  1. Open htaccess file in /public OR /public_html.
  2. Add following code in your .htaccess at top
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
  3. Save the File .
  4. Refresh the webpage, you will see same page is opened with https.
If you are getting infinite loop, then it means you are using CloudFlare or a similar CDN. Now instead of above code, use below one.
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]