Jump to content

Redirect HTTPS to HTTP


Recommended Posts

Posted

Hello everyone,

I am currently removing the SSL certificate from my board and I got stuck at redirecting all the HTTPS url's to HTTP. Now, I have the code, which I had in initdata.php for redirecting all HTTP traffic to HTTPS, but now I need to do the opposite. Here is the code:

if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
    if(!headers_sent()) {
        header("Status: 301 Moved Permanently");
        header(sprintf(
            'Location: https://%s%s',
            $_SERVER['HTTP_HOST'],
            $_SERVER['REQUEST_URI']
        ));
        exit();
    }
}

Can I do the reverse, and if so, how?

It would be really helpful if there is a way to do this with .htaccess too. I tried several Rewrite rules, but every one of them gave me wrong redirection and if you click a link from Google, you go to the homepage.

Posted

i would use .httaccess but this code should works

if ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || $_SERVER['SERVER_PORT'] == 443) {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
    exit();
}

as you want to force users to use http, there's no need to any conditions, I've changed the code

Posted

Actually, now when I tested it out more in depth, it seems that brakes somehow the "Online Members" section, and there is only me there. Or max 1 or 2 people, which is really weird, because I am sure that there's more than 2 people online. 

Posted

did you tried .httaccess?

this code should works

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{ENV:HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

or

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

i don't have apache server so i couldn't test it my self, I've copied it from here: http://stackoverflow.com/questions/8371/how-do-you-redirect-https-to-http

Posted

I've tried most of these codes from stackoverflow. The problem is that if there is any https link from Google to a topic, when you click it, you get redirected to the homepage with /index.php in the url. If I get the RewriteRule url correct, I think it should be fine. 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...