Why do .htaccess redirects work in http but not with https?

Solution 1:

There's not 100% enough info here to go on, but in the usual default SSL setup (Red Hat/CentOS/Fedora e.g.) the VirtualHost for SSL is set up in it's own container. The use of mod_rewrite requires at a minimum "AllowOverride FileInfo" to be set on the document root for it to act.

Check your config for SSL (/etc/httpd/conf.d/ssl.conf by default), ensure that it looks something like:

DocumentRoot /var/www/html
<Directory /var/www/html>
  AllowOverride FileInfo
</Directory>

The default for AllowOverride is 'None', so any other setting (such as 'All') which adds FileInfo capabilities is OK.

http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

Solution 2:

Could it be possible that mod_rewrite is not enabled for the HTTPS server, or that the .htaccess is not being used?

Check the AllowOveride permissions in use for the regular site and compare against the SSL version, probably a discrepancy. Probably introduced to improve security, if not an accident.

mod_rewrite is next to essential though, so any decent hosting provider should help sort this out.

Solution 3:

"working on apache2 + ubuntu precise"

A similar problem occured to me while I was using Slim framework and trying to remove the index.php required in the url. The reWrite worked perfectly for http but for https: it was showing url not found, which meant that the reWrite was not working.

After some hit-n-trial , I came up with this solution:

 cd /etc/apache2/sites-enabled
 sudo vim default-ssl

Change AllowOverride None to All. Similarly sudo vim ssl