How to get SSL+mod_rewrite+Zend Framework MVC working together?

我与影子孤独终老i 提交于 2019-12-07 19:17:00

问题


So, I got ZF MVC site and want to force SSL connection on everything under my /checkout/ I tried using mod_rewrite for that, so my .htaccess would look like this:

RewriteEngine on
RewriteRule (\/checkout.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R] 
RewriteRule !\.(js|ico|gif|jpg|png|css|swf|xml|avi|flv|mov|mp3|wav)$ index.php [L]

Sure enough, it does kick in SSL, but second rule, that's ZF specific and redirects everything to index.php sorta erases the protocol specification.

Unfortunately my level of proficiency with mod_rewrite is stupendously terrible. Maybe someone could help me out to solve this?


回答1:


Tim Lytle's answer is mostly there.

I'd change it be a little more strict in checking HTTPS and the flags need a delimiter.

RewriteCond %{HTTPS} !^on$
RewriteRule ^/checkout/? https://%{HTTP_HOST}%{REQUEST_URI} [R,L] 

RewriteRule !\.(js|ico|gif|jpg|png|css|swf|xml|avi|flv|mov|mp3|wav)$ index.php [L]



回答2:


This may help you, add the RewriteCond to only apply when the connection is not SSL, then add the 'L' option to your redirect rule so rewrite processing stops at that point (so the last rule doesn't override the SSL redirect).

RewriteCond %{HTTPS} !on
RewriteRule (\/checkout.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [RL] 

RewriteRule !\.(js|ico|gif|jpg|png|css|swf|xml|avi|flv|mov|mp3|wav)$ index.php [L]


来源:https://stackoverflow.com/questions/380050/how-to-get-sslmod-rewritezend-framework-mvc-working-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!