Reputation: 23
At the moment, there are two versions of my site. One with a https://-certificate, one without. I want to 301 redirect all users on the http version of my site, to the https:// version of my site.
That does not seem possible, since creating a redirect will result into a infinite loop of redirects. How can I solve this?
Upvotes: 2
Views: 37
Reputation: 16
Another option would be to use this snippet:
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
That worked for me aswell.
Upvotes: 2
Reputation: 16
You could use something like this:
<script language="JavaScript">
function redirectHttpToHttps()
{
var loc = window.location.href+'';
if (loc.indexOf('http://')==0){
window.location.href = loc.replace('http://','https://');
}
}
redirectHttpToHttps();
</script>
This code snippet detects when a user in on the http version of your site, and then rederects the user to the https version. Just copy and past the code in the head of your pages, and you are good to go.
Upvotes: 3