URL rewrite stopped working with https URL - .htaccess

I am developing a PHP based website. I made it live with HTTP URL and URL rewriting.
let suppose my domain is www.abc.com
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$
RewriteRule ^([^/]*)/([^/]*)$ index.php?%{QUERY_STRING}&current_event=$1 [L]
And I access my site as http://www.abc.com/article it works fine.
Now my client installed SSL certificates on server and I want to change URL to HTTPS but accessing https://www.abc.com/article gives me 404 error.
Please guide me how can I make my above rules work with HTTP/HTTPS both.

Related

.htaccess url rewriting issue: http to https with exception for a directory

I am currently using the following .htaccess code to rewrite:
http://force-t.fr to https://www.force-t.fr
http://www.force-t.fr to http://www.force-t.fr
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.force-t.fr$
RewriteRule ^(.*) https://www.force-t.fr/$1 [QSA,L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://www.force-t.fr/$1 [R=301,L]
Now, I need to add two exceptions :
All url starting with force-t.fr/iot/ needs to be accessible via http or https.
IE8/XP users needs to access the www.force-t.fr website in http only
(SNI is not supported by IE8/XP and my certificat is not working for them.)
I don't know how to do this and spend two hours searching without success.

Magento Redirect https to http home page

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]

Redirect all the data served by https to http

So, here is the situation:
We are running a website which is powered by Drupal. Sometime ago, it was decided that the website should be served as SSL. The settings to redirect the site from http to https was done by a guy who is not with us anymore.
I can see in the .htaccess file the following lines
#Redirect http to https
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://docs.dev.domain.com/$1 [R,L]
mydomain.com points to the root of the LAMPP server and my site is in a folder inside the webroot (docs.dev.domain.com/mysite).
Now, it has been decided that the SSL is not needed and it has to be removed and all the pages must be served via http (301 redirect).
When I do that in the .htaccess file by using the RewriteRule to redirect a URL (e.g. https://docs.dev.domain.com/mysite/content/book) to http when a user visits https by using:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
#Redirect HTTPS to HTTP
RewriteCond %{SERVER_PORT} ^443$
#RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://docs.dev.domain.com/mysite/$1 [R=301,L]
#even tried this - RewriteRule ^(.*)$ http://docs.dev.domain.com/$1 [R=301,L]
but it redirects every request on https to http://mydomain.com/mysite/index.php (even the urls like (https://docs.dev.domain.com/mysite/content/book/1 which should ideally be redirected to its http counterpart).
How can I remove the https so that my dynamic URLs are served via plain http?
Sorry if this is very novice problem.
This is happening because you have a routing rule before the redirect. The rewrite engine will loop until the URI comes back unchanged, and at that point, it evaluates if the URI needs to be passed onto other modules in order to handle redirecting or proxying.
That means your request is getting routed to index.php, then the rewrite engine loops, then it sees that the request (which at this point is simply /index.php) needs to be redirected, so the request gets flagged to be redirected. Then mod_rewite redirects, but by now, the URI is mangled by your routing rule.
You need to swap the order:
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://docs.dev.domain.com/mysite/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
Enabling SSL or disabling it in Drupal has very easy method by enabling/disabling a module. You should check the module name securepages & if it is there you just need to disable it for disabling HTTPS...
Then you can go to your YOURSITE/sites/default & look into settings.php & if $base_url is defined then just remove the 'S' from 'HTTPS'.
You are done...
I don't think that guy enabled it from .htaccess & so I gave my answer even after you solved it by Jon Lin answer..

.htaccess url rewrite for ssl https redirection

I've used different codes provided here on other questions' solutions and on the internet. I'm really not savvy with htaccess. Bought and confirmed working SSL Certificate, but I'm new to applying these redirects.
Goal:
I need to rewrite http to https on the following directories.
http://mydomain.com/products-page/checkout
http://mydomain.com/products-page/your-account
http://mydomain.com/wp-login
I'm on shared hosting via Dreamhost. I have a dedicated IP, if that helps.
Initial code I was using recommended to me by a Dreamhost representative:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} wp-login
RewriteRule ^(.*)$ https://mydomain.com/wp-login/$1 [R,L]
Try these rules in the htaccess file in your document root.
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} ^(/wp-login|/products-page/checkout|/products-page/your-account)
RewriteRule ^(.*)$ https://mydomain.com/$1 [R,L]
The first condition checks if the request isn't HTTPS, the second checks if the request starts with either /wp-login, /products-page/checkout, or /products-page/your-account, and if both apply, then the rewrite simply takes the entire URI and redirects to https://.

SSL with Codeigniter htaccess

OK so i'm having a bit of trouble with .htaccess.
I'm using Codeigniter and have just installed a SSL certificate. It's working great except I don't get the blue bar in Firefox, it says 'Your connection to this site is only partially encrypted'
Here's my .htaccess file:
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (signin)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(signin)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
I only want to force SSL on some pages, to start with the signin page (mydomain.com/signin). It seems to remove the index.php/ in the URL fine and it does seem to be forcing the SSL for that page but there's no blue bar :(
I also changed my base_url to the following in the config file to allow http and https:
$config['base_url'] = $config['base_url'] = "http".((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "")."://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
Any help is most appreciated :)
I think the error is caused by having elements in your page which are downloaded using HTTP instead of HTTPS.
You need to make sure that you either reference all the elements in the page with relative URLs or absolute URLs with the proper protocol (HTTPS instead of HTTP).

Resources