Exclude a directory from https redirects - php

I want to exclude "dir2" directory from my http to https redirect so I added the following htaccess directive:
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} dir2 [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]
and then test it by visiting the following url:
http://example.com/dir2/ok.txt but I was redirected to https://example.com/dir2/ok.txt.
Website is using Opencart 2.x under php5.6, EncryptSSL and Cloudflare's DNS. Cloudflar's Crypto settings are as follows:
SSL: Full(Strict)
Always Use HTTPS: On
Automatic HTTPS Rewrites: On
Here is the full .htaccess: https://pastebin.com/U5k5wj4K
Can you please help me out?

You can not add an htaccess rule. Because in this case, this is only for the exchange between the Cloudflare server and yours.
Add a Cloudflare rule from their control panel:
Cloudflare -> Page Rules -> Create Page Rule
And change the settings for your directory (not Always Use HTTPS and no Automatic HTTPS Rewrites)

Related

WordPress NOT redirecting from http to https SSL

I have my WordPress Address (URL) and my Site Address in the WordPress settings as my url: https://example.com/blog but when I type in http://example.com/blog, it doesn't redirect it to the SSL version, even though I have the site address as https.
I disabled all the plugins and switched to the default theme but this still occurs. Any reasons as to why this is happening or solutions?
You still have to redirect 'http' to 'https'.
You have several options, here are a couple:
Option 1
In your .htaccess file you can add:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Just be sure to change www.example.com to whatever your domain should be (you don't need the www. if you don't want it.)
Option 2
Change your DNS to CloudFlare (free) and change the settings according to this:
https://support.cloudflare.com/hc/en-us/articles/200170536-How-do-I-redirect-all-visitors-to-HTTPS-SSL-
However, if you want to use www. I recommend using two page rules so that you can redirect http to https and add www. in a single redirect. Doing both in a single redirect can be better for SEO. For both page rules, select the setting called "Forwarding URL" and "301" and make the rules as follows:
http://*example.com/*
to
https://www.example.com/$2
and
https://*example.com/*
to
https://www.example.com/$2
This is assuming that you are not using subdomains. If you are, let me know and I can update the answer with rules that will accommodate subdomains.
You forgot to update .htaccess file after installing SSL. So you should add the following code to your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
After that, for cross-checking regarding your website all pages are properly redirected to https or not, follow steps & use tools mentioned in this resource.

Redirecting Subdomain to HTTPS WWW URL using Apache Virtual Host

I was wondering how do you redirect a subdomain for both HTTP & HTTPS to a specific URL.
I want it to go from:
http://test.example.com to https://www.example.com/test
and
https://test.example/com to https://www.example.com/test
Hope this will help you out, as it is working for me.
Check this .htaccess code here
RewriteEngine on
RewriteCond %{HTTP_HOST} ([a-z]+)\.(example\.com) #checking domain and subdomain
RewriteRule ^(.*)$ https://www.%2/%1 [R=301,L] #redirecting

How to redirect https request to http in magento?

My magento site is loading well on http request, http://my-magento-site.com. But when I try lo load using https://my-magento-site.com It redirect to an error page, https://my-magento-site.com/cgi-sys/defaultwebpage.cgi . How do I prevent this, and redirect to http request ?
I tried to add this code on my root .htaccess file but not redirect,
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
How do I fix this ?
If .htaccess Rewrite rule is not working then you can set this by magento settings.
Goto >> system >> configuration >> web{under general tab}
You will find unsecure and secure tabs.
Write
Base URL http://my-magento-site.com in both URLs.
You will always redirect to http:// only

Https Redirection Issues

I'm using Cloudflare's SSL on Flexible (Free) and it works perfectly fine.
I have setup all files and links from https:// to // to make them work over https.
I have also set the following in my .htaccess file to make any client go from http to https automatically:
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.*)$ - [env=askapache:%2]
The issue with the .htaccess code is that it only changes http to https on the root index file of my site for example, http://example.com/index.php will redirect to https but http://example.com/folder/index.php wont.
My second issue is even if I do a simple href="https://example.com/folder/index.php" or href="//example.com/folder/index.php" it will just bring me to the basic http url.
If you are using CloudFlare, you can define to always use SSL in the page rules.
For .htaccess (recursive):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Force /news folder to HTTP in .htaccess

We have a section of our site which uses https to login securely, however when you visit this page and click away, you continue to view the site in HTTPS. This causes display issues on any pages using the http://www.domain.com/news/ URL.
How can we force all pages under the http://www.domain.com/news/ folder to use HTTP rather than HTTPS?
It's the opposite of requiring https, so with the condition of https on, rewrite this specific dir with deeper path to the http version.
RewriteEngine on
RewriteCond %{HTTPS} on
RewriteRule ^news/(.*) http://%{SERVER_NAME}/news/$1 [L]
Instead of SERVER_NAME, you can use HTTP_HOST when your site is accessed with a server-alias and you don't want to change that.
Be aware that links to https-requiring pages should be use https explicitly, or have a rewrite-rule of their own.
Place this 301 redirect rule in /news/.htaccess:
RewriteEngine on
RewriteBase /news/
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}/%{REQUEST_URI} [L,R=301,NE]

Categories