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

So, I have a ZF MVC site and you want to force an SSL connection to everything under my / checkout / I tried using mod_rewrite for this, so my .htaccess will 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] 

Of course, it does use SSL, but the second rule that ZF defines and redirects everything to index.php sorta erases the protocol specification.

Unfortunately, my level of ownership of mod_rewrite is terribly terrible. Maybe someone can help me solve this?

+2
source share
2 answers

Tim Lilt answers mostly there.

I would change it a bit more stringent when checking HTTPS, and checkboxes need a separator.

 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] 
+3
source

This may help you, add a RewriteCond to apply only when the connection is not SSL, then add the ā€œLā€ parameter to your forwarding rule to rewrite processing at this point (so the last rule does not cancel 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] 
+1
source

All Articles