Primoz Rome
Primoz Rome

Reputation: 11031

.htaccess allow one url to be accessed either via HTTPS or HTTP

I have a rewrite rule in .htaccess that redirects our site to HTTPS

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I need to leave one url open to work both HTTP and HTTPS (http://www.myhost.com/api and https://www.myhost.com/api). How do I need to modify my above code

Upvotes: 0

Views: 428

Answers (1)

Abhishek Gurjar
Abhishek Gurjar

Reputation: 7476

Try below rule,

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/support/registration_service
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Above rule excluding the uri /api to be forced to https so you can use www.myhost.com/api for both scheme.

Upvotes: 1

Related Questions