0

At wits end with this. My project setup below:

static web hosting: www.myproject.com
   +subdomain api.myproject.com
       +A record -> AWS Beanstalk

API (Beanstalk)
   +/v1 non HTTPS
   +/v2 HTTPS

I need to enforce HTTPS on api.myproject.com/v2 but allow non encrypted traffic to continue flowing to api.myproject.com/v1

Below is my current htaccess. I've tried many variations based on my reading, all fail. I AM able to redirect all www traffic, so I know the file can be effective.

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^api\.myproject\.com$ [NC]
RewriteCond %{REQUEST_URI} v1
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I read this as IF NOT https AND host is api.myproject.com AND uri contains v1 THEN redirect to HTTPS. Thanks

Half_Duplex
  • 5,102
  • 5
  • 42
  • 58
  • Your rule correctly redirects `http://sub.example.com/v1` to `https://sub.example.com/v1` . Try clearing your browser cache or use a different browser to test the url. – Amit Verma Jul 07 '18 at 16:05
  • If you are behind a proxy server then there is a different RewriteCond variable to check `https/http` connection ,see the #2 answer on this post https://stackoverflow.com/questions/4398951/force-ssl-https-using-htaccess-and-mod-rewrite – Amit Verma Jul 07 '18 at 16:15
  • Thanks. My API does use the Amazon load balancer mentioned in the answer, but I don't think I'm getting a redirect loop... my request doesn't appear to be triggering the rule. – Half_Duplex Jul 07 '18 at 16:53
  • Even creating a sub directory root for the subdomain and adding a working htaccess file for the path does not work. Is this all due to my subdomain having an A record? – Half_Duplex Jul 07 '18 at 17:14

0 Answers0