简体   繁体   中英

zend https redirect all requests

i want to redirect all request to my zend web application to the https url i tried this in the .htaccess file and am getting an infinite redirect

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

any ideas? i have tried a couple of things and none have worked consistently so far.

If I copy your rules, I don't seem to end with an infinite redirect, it works fine.

Here is a ZF plugin I use to force https, rather than using .htaccess . You could try this and see if it works:

<?php

class Application_Plugin_SslCheck extends Zend_Controller_Plugin_Abstract
{
    public function routeShutdown(Zend_Controller_Request_Abstract $request)
    {
        $sslModules = array('admin', 'default'); // modules that require ssl
        $module     = $request->getModuleName();

        if (in_array($module, $sslModules)) { // require SSL
            if (APPLICATION_ENV == 'production') { // only require ssl in production mode
                if (!isset($_SERVER['HTTPS']) || !$_SERVER['HTTPS']) { // if request is not secure, redirect to secure url
                    $request    = $this->getRequest();

                    $url        = 'https://'
                                . $_SERVER['HTTP_HOST']
                                . $request->getRequestUri();

                    $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
                    $redirector->gotoUrl($url);
                }
            }
        }
    }
}

To run it, just register it with the front controller in your bootstrap:

Zend_Controller_Front::getInstance()->registerPlugin(new Application_Plugin_SslCheck());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM