I've got a slight problem, this is what i'm using to force https to the checkout directory, just a precaution but the problem is once you go back through to the main pages it inserts www into the URL.
This is a problem as the rest of the sight does not use a www, can anyone suggest how to addapt this to remove/ keep out the www
# force https for all URLs in /checkout
RewriteCond %{HTTPS} =off
RewriteRule ^x9 https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# force http for all other URLs that are not in /checkout
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/x9
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Edit
If you say it's not that section above. This problem only started after the above code was added though, Ive never had this problem before and the code below has been on my site for several months.
#Take off index.html
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . http://www.%{HTTP_HOST}%1 [R=301,NE,L]
In that case keep your .htaccess like this:
#Take off index.html
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%1 [R=301,L]
# force https for all URLs in /checkout
RewriteCond %{HTTPS} =off
RewriteRule ^x9 https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# force http for all other URLs that are not in /checkout
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/x9
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Related
I want to redirect my entire site from http to https except for one page ( a file to be download actually ) but am having troubles
I am currently using
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
from this post ... htaccess redirect to https://www
but have not figured out how to exclude the one file I need.
it is more or less
http://www.something.com/phone/version/currentversion.txt
I tried redirecting the https version of it back to the http version, but I got an error that said something along the lines that I was in an endless loop of resolution and it would not work
any help would be appreciated
A simple mod_rewrite exception should work:
RewriteEngine On
RewriteCond %{REQUEST_URI} !/phone/version/currentversion.txt
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I have site with https
But I need specific folder should be http.
How can we achieve it ?
e.g.
my site is
https://www.mywebsite.com
I want folder1/subfolder1 should be forced to http://
e.g. http://www.mywebsite.com/folder1/subfolder1
I searched on net...but maximum search show how to force http to https
I tried .htaccess as follows :
try 1.
RewriteRule ^(/folder1/subfolder1)($|/) - [L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
try 2.
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/folder1/subfolder1
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
But it didn't work..
You can use these rules in your site root .htaccess:
RewriteEngine On
# force https on everything except /folder1/subfolder1
RewriteCond %{THE_REQUEST} !\s/+folder1/subfolder1[/?\s] [NC]
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
# force http on /folder1/subfolder1
RewriteCond %{THE_REQUEST} \s/+folder1/subfolder1[/?\s] [NC]
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Make sure to clear your browser cache or use a new browser for testing.
Of the four possible variations of my site URL, I would like to redirect to https://example.com (https:// non-www).
My .htaccess file contains the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This redirects from http:// to https:// but not from www to non-www
Any help much appreciated.
Make your first rule generic like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*?)/?$ https://%1/$1 [L,R=301,NE]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} !on
RewriteRule ^(.*?)/?$ https://%1/$1 [L,R=301,NE]
Make sure to clear your browser cache before testing this change.
I'm trying to force HTTPS using the .htaccess of a site running expression engine.
As of right now you are able to go to the site using https:// but when i add any of these rules it presents a redirect loop.
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
or
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
or
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mydomain.com/$1 [R,L]
and also this fancy one
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
and I've also tried rearranging all the rules on each of them so I'm pretty sure it has something to do with the conditions matching when they shouldn't.
I've also read some things about load balancers redirecting things counter to the .htaccess
from here:
.htaccess redirect loop when trying to add forced HTTPS rule (Amazon Elastic Beanstalk) and here: https://serverfault.com/questions/283525/force-ssl-on-one-page-via-htaccess-without-looping
i think my client is using inmotion hosting but I don't have access to the load balancer settings so I want to make sure that is the problem.
here is the entire htaccess. I removed some of the default expression engine stuff, but it was also not working before I did that.
<IfModule mod_rewrite.c>
# Enable Rewrite Engine
# ------------------------------
RewriteEngine On
RewriteBase /
# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# RewriteCond %{HTTP:X-Forwarded-Proto} !https
# RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteCond %{THE_REQUEST} ^GET
RewriteRule ^index\.php(.+) $1 [R=301,L]
# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|images|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
(I have them disabled because the site is live)
You might be better off posting on the EE Stack Overflow site. Or have a search on it as there's a few answers relating to https and .htaccess
Here's a post I replied to previously with an answer you might want to try:
https://expressionengine.stackexchange.com/questions/7601/adding-a-htaccess-redirect-to-https-that-plays-nicely-with-existing-ee-htacces/7659#7659
If this condition didn't work:
RewriteCond %{SERVER_PORT} !^443$
Try this:
RewriteCond %{HTTPS} !=on
Instead of this one:
RewriteCond %{HTTPS} off
I've had the same situation and here's what just worked for me with an EE3 site:
#non-www to www
RewriteCond %{HTTP_HOST} !^www\.domainname\.co.uk$
RewriteRule (.*) https://www.domainname.co.uk/$1 [R=301,L]
# Force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
I'm trying to force a user to be redirected to the non-www website, and, force https.
I've got this which sort of work, but doesn't force https, when http is entered.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://site.com\.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Any ideas on what I'm doing wrong?
Try this rule:
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
Based on Gumbo's comment : "the TLS/SSL connection is established and certificate is validated before it is handed down to HTTP and the HTTP redirection takes place"
I gave this a try (which seems to work):
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.blahblah.com/$1 [R,L]
RewriteCond %{HTTP_HOST} ^www\.blahblah\.com [NC]
RewriteRule ^(.*)$ https://blahblah.com/$1 [L,R=301]
please tell me if there is something wrong with this approach.
The only set of rules that works for me is the following
# match any URL with www and rewrite it to https without the www
RewriteCond %{HTTP_HOST} ^(www\.)(.*) [NC]
RewriteRule (.*) https://%2%{REQUEST_URI} [R=301,L]
# match non https and redirect to https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
The order matters, it prevents a third redirect in some cases.
With this code I rediret from http and www and none www to https none www. Just pay attenstion that the place you insert the code in htaccess is important:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]