1

I have read a lot about this, but i still can't figure it out for my case. I am trying to force all http requests to go to https except for 2 pages. Those 2 pages requests have parameters passed to them. Here is the code i am using currently:

# Force go to https if user isn't asking for a url that has 'register_user.php' or 'register-customer' inside the url:
    RewriteCond %{SERVER_PORT} 80 
    RewriteCond %{REQUEST_URI} !^/register_user.php$  [OR]
    RewriteCond %{REQUEST_URI} !^/register-customer$ [NC]
    RewriteRule ^(.*)$ https://www.myWebsite.com/main-folder/$1 [R,L]

# Force go to http if user is asking for a url that has 'register_user.php' or 'register-customer' inside the url:
    RewriteCond %{SERVER_PORT} !80 
    RewriteCond %{REQUEST_URI} ^/register_user.php$   [OR]
    RewriteCond %{REQUEST_URI} !^/register-customer$ [NC]
    RewriteRule ^(.*)$ http://www.myWebsite.com/main-folder/$1 [R,L]

This code doesn't do the required job. Is there something wrong with it?

Brad
  • 4,457
  • 10
  • 56
  • 93
  • Possible duplicate of [How to redirect all HTTP requests to HTTPS](http://stackoverflow.com/questions/4083221/how-to-redirect-all-http-requests-to-https) – Jeremy Harris Nov 23 '16 at 17:51
  • @Jeremy .. Not exactly! ... I want to exclude specific pages from this redirect. – Brad Nov 23 '16 at 17:58

1 Answers1

0

You should use THE_REQUEST instead of REQUEST_URI as REQUEST_URI may change due to other rules.

Also you should keep these 2 rules at the top before other rules:

# Force go to https if user isn't asking for a url that has 'register_user.php' or 'register-customer' inside the url:
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/(register-customer|register_user\.php)[?/\s]  [NC]
RewriteRule ^ https://%{HTTP_HOST}/main-folder%{REQUEST_URI} [R=301,NE,L]

# Force go to http if user is asking for a url that has 'register_user.php' or 'register-customer' inside the url:
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /(register-customer|register_user\.php)[?/\s]  [NC]
RewriteRule ^ http://%{HTTP_HOST}/main-folder%{REQUEST_URI} [R=301,NE,L]

Make sure to clear your browser cache before testing this change.

anubhava
  • 761,203
  • 64
  • 569
  • 643