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 2 of 2
Like Tree1Likes
  • 1 Post By Inigoesdr

Thread: How to redirect all http requests to https, with exceptions?

  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Posts
    302
    Thanks
    68
    Thanked 8 Times in 8 Posts

    How to redirect all http requests to https, with exceptions?

    I need to be able to redirect all requests to http://www.example.com and http://example.com to https://secure.example.com

    In addition, I need to add exceptions to this rule. E.g. http://www.example.com/exception1.php and http://www.example.com/exception2.php should NOT be redirected.

    Google searches have turned up the following code, which redirects http://www.example.com and http://example.com to https://www.example.com, with no exceptions:

    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    It seems that with this code, I am halfway there ...

    How can I adapt this code for my needs?
    Last edited by XmisterIS; 02-26-2014 at 11:19 AM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You need to specify the domain explicitly since it's changing:
    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://secure.example.com%{REQUEST_URI} [R,L]
    XmisterIS likes this.


  •  

    Posting Permissions

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