1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

[htaccess] Redirect primary domain from http to https but exclude all subdomains

Discussion in 'Apache' started by slaxy, Sep 9, 2015.

  1. #1
    Hi all

    I want to redirect my primary domain to https (http:// www. website.com to https:// www. website.com) and exclude all sub domains. (http:// xyz. website.com to remain as http:// xyz. website.com)

    I have been on google for too long and couldnt find the right solution, please help

    My .htaccess file

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https:// %{HTTP_HOST}%{REQUEST_URI} [R,L]

    - Slax
     
    slaxy, Sep 9, 2015 IP
  2. imgtrex

    imgtrex Peon Affiliate Manager

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    3
    #2
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} www.mydomain.com
    RewriteRule (.*) https://www.mydomain.com/$1 [R=301,L]
    Code (ApacheConf):
    I think the rule could be just
    
    RewriteRule (.*) https://www.mydomain.com$1 [R=301,L]
    Code (markup):
    leaving out the extra slash, which should be included in the rule match. But I always forget whether that works or not.
     
    imgtrex, Sep 12, 2015 IP
  3. ProxyRadar

    ProxyRadar Greenhorn

    Messages:
    22
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    20
    #3
    What is wrong with your current .htaccess? Seems like it should do the job
    Additionally, you should exclude robots.txt file from this rule, to make it accessible for Search Engines like this

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} !/robots.txt
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    PHP:
     
    ProxyRadar, Sep 18, 2015 IP