symfony - Symfony2 route that enforces HTTPS without redirection -
how can define route in symfony2 requires https not automatically redirect http?
for example, know can set "scheme", such as:
demo: resource: "@demobundle/controller/democontroller.php" type: annotation prefix: /api/demo schemes: [https] this redirect user "http://www.example.com/api/demo/{route}" "https://www.example.com/api/demo/{route}". however, want attempt use "http" fail 404 or 500 error, while direct attempt use "https" routed successfully.
update:
i kept "schemes" parameter in routing file , added following .htaccess file:
rewritecond %{server_port} 80 rewritecond %{request_uri} api rewriterule ^(.*)$ %{env:base}/ssl-only.php [r,l]
i recommend remove schemes: [https] routing, , instead check scheme in controller if not https redirect specific error page want:
public function yourroutingaction() { if ($this->getrequest()->getscheme() == 'http') { return $this->redirect($this->generateurl('specific_route', 301)); } //otherwise continue process //you can change status code whatever want instead of 301 }
Comments
Post a Comment