I want user redirect to https insetad of http just after login in my new website made in zend framework2. please help.
I there any method available in zend freamework2 to get current used protocol(http or https).
I want user redirect to https insetad of http just after login in my new website made in zend framework2. please help.
I there any method available in zend freamework2 to get current used protocol(http or https).
You can redirect the user to the https version of a page inside the application. Above solution simply redirects all requests to it's http variant, and only for Apache. I would rather do it inside the application (then you're more in control) and make it server agnostic (what happens when you switch to nginx?)
An example is based on an answer I gave earlier here: ZF2 and force HTTPS for specific routes
The solution: create a controller plugin which you can call every time you need it. Specify the pages you need to force a redirect (i.e. the page you show the login form):
And then you could create a controller plugin (call it
ForceHttps
) to return a response when the user should be redirected:What happens is
null
), force the canonical version (i.e. with a full scheme and domain name) and reuse the current route match parameters (thetrue
as last parameter).on your
.htaccess
write these rulesnote that
public/index.php
is the root so you have to modify it andwww.yoursite.com
toofor
logged-in user
you have to do withphp