Magento Redirect https to http home page - .htaccess

Google has indexed the home page of my website with https. But I need to redirect https to http only this page. I'm using Magento and today I have a rule that removes the htaccess www of my domain. Every rule I created to redirect the main page of https to http didn't work. Anyone have a solution?
thank you

Try
#Redirect your Homepage from HTTPS to HTTP
RewriteCond %{HTTPS} on
RewriteRule ^$ http://%{HTTP_HOST} [L,R]
See http://www.activo.com/redirect-https-to-http-for-any-homepage/

Set this up in Magento first:
Oopen admin panel and visit System -> Configration -> Web panel and set:
Base URL (unsecured) as http://www.domain.com/magento/.
Base URL (secured) as https://www.domain.com/magento/.
then set:
Use Secure URLs in Frontend = Yes
Save your settings, clear your Magento cache
Finally in Magento's .htaccess add these lines just below RewriteBase line:
RewriteCond %{HTTPS} off
RewriteRule (?!^(index\.php/?|.*\.css|.*\.js|.*\.gif|.*\.jpe?g|.*\.png|.*\.txt|.*\.ico|)$)^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
RewriteCond %{HTTPS} on
RewriteRule ^(index\.php/?|.*\.css|.*\.js|.*\.gif|.*\.jpe?g|.*\.png|.*\.txt|.*\.ico|)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NC]

Use this with 301 http request for google indexer.
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

If you use cludeflare then this redirect is not working
place try with below on you htaccess file and it cloudflare format
Http to Https redirection:
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule ^(.*)$ https://www.domain.com/$1 [L]
See note:
When using Flexible SSL with CloudFlare, your origin server will always accept requests over HTTP (port 80). In order to properly redirect a user surfing securely over HTTPS, you should modify your rewrite rules to use the CF-Visitor HTTP header. The CF-Visitor header contains the following:
CF-Visitor: {"scheme":"http"}
or
CF-Visitor: {"scheme":"https"}
To redirect a user from HTTP to HTTPS, you can use the following:
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule ^(.*)$ https://www.domain.com/$1 [L]
Similarly, to require all traffic go over HTTPS on CloudFlare, you can use the following:
RewriteCond %{HTTP:CF-Visitor} !'"scheme":"http"'
RewriteRule ^(.*)$ https://www.domain.com/$1 [L]

Related

How to correctly redirect all http requests to https

I have a functional URL shortening site. Recently I added SSL to the website and configured the .htaccess for proper redirecting. The issue is that all of the http:// requests, redirect back to the homepage https://websi.te
Currently, I've tried setting up redirecting as follows:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
An example of what's going wrong:
User types http://websi.te/keyword or websi.te/keyword and they are redirected to https://websi.te instead of https://websi.te/keyword
Change your rewrite to this:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
$1 is first group match ^(.*)$, it's your request.

Use .htaccess to force HTTPS only on 1 page & 1 directory?

We need to force HTTPS only for one specific page and one directory, i.e. /login.php and anything in the /forum directory. All other pages on the site should be forced into HTTP (even if manually requested as HTTPS).
I'm hitting roadblocks getting this to work via .htaccess... can anyone help? Thanks so much!
You can use the following rewriteRules :
RewriteEngine on
#force https for /login.php and /forum
RewriteCond %{HTTPS} off
RewriteRule ^(login\.php|forum/.*)$ https://%{HTTP_HOST}/$1 [NE,L,R]
#redirect everything else to http if requested as https
RewriteCond %{HTTPS} on
RewriteRule ^((?!login\.php|forum/.*).*)$ http://%{HTTP_HOST}/$1 [NE,L,R]

Redirecting http to https via .htaccess

Currently I have the following in my .htaccess file for a forum site.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^/?$ http://example.com/forums/ [L,R=301]
It works perfect for redirecting everything like (http)://example.com, www.example.com, (http)://www.example.com etc. to example.com/forums which is what I wanted.
I now want to have everything redirect to (https)://example.com/forums but am running into problems with existing links such as example.com/forums/stuff.
I can only get example.com to redirect to https://example.com/forums, any direct links such as example.com/forums/stuff etc. will not redirect to the https version, any ideas?
You need 2 redirect rules. One rule to redirect landing page to forums page and another rule to redirect http -> https:
RewriteEngine On
# redirect landing page to /forums/
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com [NC]
RewriteRule ^/?$ https://%{HTTP_HOST}/forums/ [L,R=301]
# redirect http -> https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

Redirecting https to http expect one url with htaccess

I was trying to redirect my webpage to normal http but one specific url should be redirect to https.
I tried this:
RewriteCond %{HTTPS} off
RewriteRule ^site-name\.html$ https://domain.com/site-name.html [L,R=301]
But this way, the normal website is reachable through http and https.
Maybe you guys can help me with that.
You can have another to redirect https->http for all other pages:
RewriteCond %{HTTPS} on
RewriteRule !^site-name\.html$ http://domain.com%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^site-name\.html$ https://domain.com%{REQUEST_URI} [NE,L,R=301]

.htaccess Redirect Specific Subdomain from HTTPS back to HTTP

I am using .htaccess to redirect all requests (except to subdomains) from HTTP to HTTPS. This code works for me just fine:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !=m.example.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
However, it does not prevent the user from manually attempting to access the subdomain using the HTTPS (The SSL that I have does not cover subdomains and shows trust error when used for sub-domains).
Now, I am wondering:
1-How can I redirect all HTTPS requests to subdomain back to HTTP?
2-How can I modify this code to dynamically apply the subdomain restrictions to other subdomains (not only m.example.com)
1) If the certificate doesn't include m.example.com, you can never send the redirect, since the browser will refuse to make a connection. So there is no way of doing this.
2) So all you want the htaccess to do is redirect the naked domain to https. To do this use:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
I case the certificate also includes www.example.com use
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}

Resources