Redirect all traffic to https://

Discussion in 'Apache' started by walesalex, Jan 29, 2007.

  1. #1
    Hi, how do I do this using .htaccess?

    If they enter www. or not I'd like them to be redirected to https://www.(or not)

    How do I make it so every single page on the website no matter what directories the files are in, so I can make the links http://www. and they redirect automatically to https://www. ?

    I realise I've probably talked a load of crap here but I know nothing about .htaccess but hopefully you can understand what I'm trying to do, thanks.
     
    walesalex, Jan 29, 2007 IP
  2. Kalyse

    Kalyse Peon

    Messages:
    1,221
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Kalyse, Jan 29, 2007 IP
  3. walesalex

    walesalex Peon

    Messages:
    552
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    So I put just that in .htaccess in the main directory and will it redirect all pages to their file names or back to the main index?
     
    walesalex, Jan 29, 2007 IP
  4. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #4
    RewriteEngine On
    RewriteCond %{SERVER_PORT} !^443$
    RewriteCond %{HTTP_HOST} ^(www\.)?
    RewriteRule (.*) https://%1yourdomain.com/$1 [R=301,L,NC]
    Code (markup):
    Line 1: turn rewrite engine on (self explanitory)
    Line 2: match the server port against 443 (default for SSL connection)
    Line 3: see if we requested www. (or not) and capture in backreference %1
    Line 4: intercept all requests, redirect to requested page in https://

    Hopefully that makes sense.
     
    rodney88, Jan 29, 2007 IP