.htaccess forcing http for everything but 1 folder.

Discussion in 'Apache' started by JWRmedia, Nov 18, 2008.

  1. #1
    Hi, all!

    This morning Im playing around with my .htaccess file trying to force http on all parts of my site EXCEPT a folder called /docs.
    I know how to force https for /docs, but I dont want to force https. I want the visitor to be able to use http OR https, so in the code below, its forcing http for all parts of my site.

    What Im trying to figure out is what to add to make an exception for the /docs folder.

    If someone could hep me out, Id really appreciate it.


    #Force http for everything
    RewriteEngine On
    RewriteCond %{HTTPS} on
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
    Code (markup):
    Thanks.
     
    JWRmedia, Nov 18, 2008 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    Are there any other rewrites going on for the docs folder ?

    The simple solution would be to turn off the RewriteEngine in the docs folders htaccess.
     
    joebert, Nov 18, 2008 IP
  3. JWRmedia

    JWRmedia Banned

    Messages:
    499
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey... a fellow Floridian! Yeah, in the /docs folder if I put this in an .htaccess file, it will force https for just this folder:

    
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    
    Code (markup):
    EXCEPT..... dang. I just realized that ONE file within this folder does not function properly under https, so I need to make an exception for just one file in this folder to be displayed as http...
     
    JWRmedia, Nov 18, 2008 IP
  4. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #4
    <Files "one-file.ext">
    RewriteRule ...
    </Files>
    Code (markup):
     
    joebert, Nov 18, 2008 IP
  5. evera

    evera Peon

    Messages:
    283
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Just add this condition, and replace Folder1 folder2 folder3 with your folder names. Cheers

    RewriteCond %{REQUEST_URI} !^/(Folder1|Folder2|Folder3)
    Code (markup):
     
    evera, Nov 19, 2008 IP
  6. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #6
    It is almost always better to use a subfolders htaccess than it is to use RewriteCond in a parent folder.

    If you want to know why, enable RewriteLog on a test server withh fully detailed logging and take a look at the process the RewriteEngine goes through.
     
    joebert, Nov 19, 2008 IP