I try to force all my website to https. So I did:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]
It works. The problem is that I want that http calls on mywebsite.com/api/... work too. So I add RewriteCond %{REQUEST_URI} !^/api(/.*)?.
My .htaccess is:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/api(/.*)?
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]
But it doesn't work. If I call http://mywebsite.com/api/xxx it redirects me to https://mywebsite.com/index.php ..
I don't know why. Do you have any ideas?
I use Zend 1
---- EDIT ----
Changed my .htaccess to this:
RewriteEngine On
# HTTPS
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/api(/.*)?
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php
Options +Indexes
IndexIgnore *
But still doesn't work
---- EDIT 2 ----
The new .htaccess (this one is working):
RewriteEngine On
RewriteBase /
# HTTPS
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/api
RewriteCond %{QUERY_STRING} !^/api
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]
I had to add condition with QUERY_STRING and change last redirect to index.php
Thank you @MrWhite