How to redirect a http subdomain to https subdomain?

Discussion in 'Apache' started by rimo, Mar 5, 2010.

  1. #1
    Hi,

    I was wondering how to make a redirect like this:

    I have http://sub.domain.com but I want to redirect(301) this to https://sub.domain.com.

    My controlpanel is DirectAdmin,but can't redirect it within the cp like the way I want the redirect.

    Can someone help me how to make a rewrite for htaccess ?

    Thanks in advance.

    Kind regards,
    Richard
     
    rimo, Mar 5, 2010 IP
  2. gopkris2000

    gopkris2000 Peon

    Messages:
    86
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Please try with the following redirect code in your .htaccess

    RewriteCond %{HTTP_HOST} ^sub.domain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.sub.domain.com$
    RewriteRule ^/?$ "https\:\/\/www\.sub.domain\.com\" [R=301,L]
     
    gopkris2000, Mar 5, 2010 IP
  3. rimo

    rimo Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    Thanks,just tried it,but does not work here.

    Maybe another solution?

    Richard
     
    rimo, Mar 5, 2010 IP
  4. BrianM

    BrianM Peon

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    Code (markup):
    FYI... you could have used google. ;)
     
    BrianM, Mar 6, 2010 IP