redirecting Https to http using .htaccess?

Discussion in 'Programming' started by webbhost, Jul 15, 2014.

to remove all ads.
  1. webbhost

    webbhost New Member

    Messages:
    5
    Hi all,

    I want to set up a facebook tab with some basic info (opening hours for multiple locations), however facebook requires both a https and http link for users.

    I've read that I can get the server to redirect https to http via the below code in the .htaccess file - but it isn't working for me.

    Code:
    RewriteCond %{HTTP_HOST} !^$
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    Can anyone help me to figure out why this doesn't work?

    I've tried putting it in both public_html directory .htaccess, and the directory above that (my root directory for hosting).

    Thanks on advance for anyone who can shed some light!
     
  2. webbhost

    webbhost New Member

    Messages:
    5
    having a play, I can point a http to https page - just not the other way around.

    Is a https site stored in a different location from a http page?

    When it redirects to https is says page does not exist?
     
  3. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,675
    Not unless you have set it that way.

    Has the https document root been set in httpd.conf?
     
  4. Robert-B

    Robert-B Member

    Messages:
    70
    This code works fine for me in my htaccess file

    RewriteEngine on
    RewriteOptions inherit

    RewriteCond %{HTTP_HOST} ^exampledomain.co.uk$
    RewriteRule ^(.*)$ "http://www.exampledomain.co.uk$1" [R=301,L]
     
    Last edited: Aug 4, 2014
  5. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,675
    Or you could check the request port

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

Share This Page