301 https protocol redirect to http

Asked

Viewed 3,185 times

1

  • I tried all the forms below and it didn’t work... I think there is another way to work... How do I get all my links that have "https://" redirected to the same link without www ? eg: https: // www. meudominio.com/test be redirected to https:// meudominio.com/test

  • If it didn’t work the way below, something else is wrong with your setup. I even tested them all to see which ones looped and which ones didn’t. Are you sure your . htaccess is being read and that you have the necessary permissions? mod rewrite is enabled?

4 answers

4

For cases where everything that is HTTPS should be directed to HTTP:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  • Zull, Thanks but it hasn’t worked yet dude, it keeps going to the HTTPS (I’ve already changed the . htaccess from the root and Tbn from the /blog, but it hasn’t worked).

  • You saw the @Bacco response ?

  • vi yes! But like this one written above.. it will go into infinite loop.. because the link of 2 are equal.. what changes is only https. Can you add me on the face to explain it better? Thank you very much! https://www.facebook.com/israelvitorino

4

Based on the @Zuul response, follow the version for your specific case,

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule blog/tag/dengue-mata/ http://meudominio.com/blog/tag/dengue-mata/ [R=301,L]

If you want to use parameters or some extra data after the bar, you can do so:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule blog/tag/dengue-mata(.*) http://meudominio.com/blog/tag/dengue-mata$1  [R=301,L]

Note that I have omitted the final bar to contemplate Urls without the bar as well. Adjust as needed.

Important: If your domain does not have the correct certificate, please sign in to https://, the error message will appear before redirect anyway. This is in the nature of the protocol, which first makes the connection secure, then requests the path.


Beware of pure redirect:

The redirect is excellent, but when you just switch the protocol, and the path is the same, it can go into infinite loop, as in this case:

Redirect 301 /blog/tag/dengue-mata/ http://meudominio.com/blog/tag/dengue-mata/

-1

Try this

# Permanent URL redirect
Redirect 301 /blog/tag/dengue-mata/ http://meudominio.com/blog/tag/dengue-mata/
  • You’ve created an infinite loop.

  • Leandro, but what about https ? that way you pos will go into infinite loop

-2

         var url      = window.location.href;     // Retorna a url completa

        console.log(url);

        var array = url.split(":");  // separa antes e após os :

        console.log(array[0]);

        if(array[0] == "http"){  // faz a comparação

            var trocado = url.replace("http", "https");  // faz a troca

            console.log(trocado);

            window.location.href = trocado;  // redireciona
        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.