htaccess - Switch from https (SSL) except for a URL then switch back to http

Discussion in 'Troubleshooting' started by karyng01, Apr 17, 2013.

  1. karyng01

    karyng01 aMember Pro Customer

    Joined:
    Jul 30, 2008
    Messages:
    71
    Site Running SSL
    Have setup my aMember site to run using https (SSL) for all pages, defining it under the "Fix aMember Pro License Key" screen, both licenses use https:// in their URL prefix.

    The Goal
    What I need to do is switch from https (SSL) to http for just a few URL's and then back again to https (SSL) you move off those pages.

    The Restriction
    The reason for this need is some embedded member page content HAS to come from a third-party website source that only allows http and blocks access to that content if the connection is https (SSL). There is no way round this limitation given the current setup which I don't want to change to a different service if I can fix this using htaccess.

    Example:
    All pages need to be https (SSL) apart from:
    http://www.mysite.com/members/content/p/id/26/ OR
    http://www.mysite.com/members/content/p/id/27/

    Once you move off these pages "26/27" then need to switch back to https.

    Have been fighting with this one for days using htaccess and just cant' get any of the solutions working that I found in Stackoverflow or around the Internet, in particular this one that seems to do what I want (but in reverse). aMember just seems to ignore these htaccess rule changes and I can't figure out why.

    http://stackoverflow.com/questions/...-on-all-pages-and-https-on-select-directories

    Here's my mods to the above htaccess fix. Here's the code logic:
    1. If the https is OFF and the URL's are NOT equal to the exception pages (26/27)
    2. Then rewrite the URL to be https (SSL) for all pages
    3. If the https is ON and the URL's are EQUAL to the exception pages (26/27)
    4. Then rewrite the URL to be http for these pages
    The only problem (of course) is I can't get it to work. Thanks for any help you can give.
    Aly
    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} !^(members/content/p/id/26/)$ [NC]
    RewriteCond %{REQUEST_URI} !^(members/content/p/id/27/)$ [NC]
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
     
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} ^(members/content/p/id/26/)$ [NC,OR]
    RewriteCond %{REQUEST_URI} !^(members/content/p/id/27/)$ [NC,OR]
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Aly,
    I see one issue in these rules:
    Code:
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} ^(members/content/p/id/26/)$ [NC,OR]
    RewriteCond %{REQUEST_URI} !^(members/content/p/id/27/)$ [NC,OR]
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
    
    should be
    Code:
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} ^(members/content/p/id/26/)$ [NC,OR]
    RewriteCond %{REQUEST_URI} ^(members/content/p/id/27/)$ [NC]
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
    
    What happens when you use these rules?
  3. karyng01

    karyng01 aMember Pro Customer

    Joined:
    Jul 30, 2008
    Messages:
    71
    Alex, it will be a few days before I can test this out and get back to you. Thank you for picking up on the error.

    Aly

Share This Page