.htaccess content

Discussion in 'Apache' started by pzelf, Oct 1, 2012.

  1. #1
    Im looking to redirect all traffic on my site to the https version and been struggeling with the .htaccess file for quite some time now.
    I have it partially working, but not 100%

    What i want is to redirects both http:// and http://www. traffic to the https://www. version of the site. ( in a seo friendly way)

    I added this to my .htaccess file:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

    this redirects "http" traffic to the "https://www" version if the site ( which is good) BUT i also want to redirect http://www. trafic to the https://www. version of the site.
    Does anyone have a clue on how to do this?

    any ideas are much apreciated!
     
    pzelf, Oct 1, 2012 IP
  2. RoseHosting

    RoseHosting Well-Known Member

    Messages:
    230
    Likes Received:
    11
    Best Answers:
    11
    Trophy Points:
    138
    #2
    Try with the following code

    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    Code (markup):

     
    RoseHosting, Oct 1, 2012 IP
  3. pzelf

    pzelf Well-Known Member

    Messages:
    949
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    143
    #3
    Thanks RoseHosting, this works fine
    But this is a port based redirect ( port 80)
    I really would like a URL/Directory based redirect ( for seo reasons)

    Any way this can be done?
     
    pzelf, Oct 3, 2012 IP
  4. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #4
    How about something like this:
    
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    
    Code (markup):
    Cheers!
     
    pr0t0n, Oct 7, 2012 IP