Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    49
    Thanks
    7
    Thanked 1 Time in 1 Post

    RewriteCond for SSL

    Hi all,
    I set some RewriteCond in order to redirect from some pages (80 port) to its corresponding ssl pages (443):
    Code:
    RewriteCond %{SERVER_PORT} 80 
    RewriteCond %{REQUEST_URI} /LogIn.php
    RewriteRule ^(.*)$ https://site.com/LogIn.php [R,L]
    RewriteCond %{SERVER_PORT} 80 
    RewriteCond %{REQUEST_URI} /ok.php
    RewriteRule ^(.*)$ https://site.com/ok.php [R,L]
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{REQUEST_URI} /ko.php
    RewriteRule ^(.*)$ https://site.com/ko.php [R,L]
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{REQUEST_URI} /bho.php
    RewriteRule ^(.*)$ https://site.com/bho.php [R,L]
    Is it possible to sum/summarize them in less lines?

    After that, is it possible to redirect from all ssl pages, that aren't listed above, to its corresponding non-ssl page?

    Thank you very much

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Is it possible to sum/summarize them in less lines?
    Try
    Code:
    RewriteCond %{REQUEST_URI} ^/(LogIn|ok|ko|bho)\.php$ 
    RewriteRule ^(.*)$ https://site.com/$1 [R,L]
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Maurizio1230 (07-17-2010)

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by abduraooft View Post
    Try
    Code:
    RewriteCond %{REQUEST_URI} ^/(LogIn|ok|ko|bho)\.php$ 
    RewriteRule ^(.*)$ https://site.com/$1 [R,L]
    You need to specify the port or it will start an infinite loop when someone goes to the HTTPS site.

    Maurizio1230, try this out:
    Code:
    RewriteCond %{SERVER_PORT} 80 
    RewriteCond %{REQUEST_URI} ^/(LogIn|ok|ko|bho)\.php$ 
    RewriteRule ^(.*)$ https://site.com/$1 [R,L]
    
    RewriteCond %{SERVER_PORT} 443
    RewriteCond %{REQUEST_URI} !^/(LogIn|ok|ko|bho)\.php$ 
    RewriteRule ^(.*)$ http://site.com/$1 [R,L]

  • Users who have thanked Inigoesdr for this post:

    Maurizio1230 (07-17-2010)

  • #4
    New Coder
    Join Date
    Jun 2009
    Posts
    49
    Thanks
    7
    Thanked 1 Time in 1 Post
    Thank you very much
    And what about my second question?:
    Quote Originally Posted by Maurizio1230
    is it possible to redirect from all ssl pages, that aren't listed above, to its corresponding non-ssl page?

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by Maurizio1230 View Post
    Thank you very much
    And what about my second question?:
    Unless I'm misunderstanding you, that should be covered with the second rewrite I posted above.

  • #6
    New Coder
    Join Date
    Jun 2009
    Posts
    49
    Thanks
    7
    Thanked 1 Time in 1 Post
    Oh. thank you very much. Sorry but I didn't see the not Logical Operator "!" in your code. You are great!!!
    May I ask you how to redirect from http://site.com/blabla/EVERYTHING.php to https://site.com/blabla/EVERYTHING.php? It should be included in the .htaccess where I added the above code.

    I try to do it in this way but it doesn't work:
    Code:
    RewriteCond %{SERVER_PORT} 80 
    RewriteCond %{REQUEST_URI} ^/(LogIn|ok|ko|bho)\.php$
    RewriteCond %{REQUEST_URI} ^/blabla/^.*$
    RewriteRule ^(.*)$ https://site.com/$1 [R,L]
    I use ^.*$ because ^.*$ means matching everything.

    Thank you very much inigiesdr.
    Last edited by Maurizio1230; 07-18-2010 at 06:01 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •