The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Http to Https Redirection

Discussion in 'General Discussion' started by lloyd_tennison, Jun 25, 2007.

  1. lloyd_tennison

    lloyd_tennison Well-Known Member

    Joined:
    Mar 12, 2004
    Messages:
    698
    Likes Received:
    1
    Trophy Points:
    18
    I am trying to have a http redirection to https. Everything I see, seems to be real simple, but does not work both ways.


    Domain = mydomain.com
    Directory = payme
    File = index.php


    So, I have an .htaccess file in the directory payme that states:

    Code:
    <IfModule mod_ssl.c>
    SSLRequireSSL
    </IfModule>
    <IfModule !mod_ssl.c>
    # no non-ssl access
    Redirect permanent / https://www.mydomain.com/
    </IfModule>
    Everything I read says that should work, but not.

    I also tried:

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.mydomain\.com
    RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301]
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^index\.php$ https://mydomain.com/payme/ [R=301,L]
    
     
    #1 lloyd_tennison, Jun 25, 2007
    Last edited: Jun 26, 2007
  2. lloyd_tennison

    lloyd_tennison Well-Known Member

    Joined:
    Mar 12, 2004
    Messages:
    698
    Likes Received:
    1
    Trophy Points:
    18
    It seems even with only this in .htaccess

    Code:
    <IfModule !mod_ssl.c>
    # no non-ssl access
    Redirect  permanent / http://www.google.com
    </IfModule>
    Nothing happens. Opens index.php in that directory and does not send to google.
     
  3. expedio

    expedio Active Member

    Joined:
    Jun 30, 2007
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    6
    Try the following code, it is working nicely on my site.

    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    RewriteRule www(.*) https://yourHTTPSdomain.com%{REQUEST_URI}
    
    
     
  4. billy79

    billy79 Active Member

    Joined:
    Dec 15, 2004
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    6

    I gave it a try and for the most part it works but there is one issue.

    The cert is for www.domain.com. So when someone goes to http://www.domain.com it redirects them to https://www.domain.com no problem.

    However when someone goes to http://domain.com it redirects them to https://domain.com, since the server is made for www.domain.com that gives them a warning in the browser that the cert does not match the URL.

    Does anyone have any ideas on what modrewrite command may work to solve that dilemma.

    Thanks in advance.
     
Loading...

Share This Page