I would like to redirect every url of my website from http:// to https://
My problem is that I alerady have a routing system in my .htaccess :
RewriteRule ([^.]+)\.html$ index.php?/$1 [QSA,L]
I tried to add this, but the route is broken :
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Can anyone help me ?
Thanks !
Add HTTP to HTTPS before old RewriteRule:
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
RewriteRule ([^.]+)\.html$ index.php?/$1 [QSA,L]
I found the good statements :
RewriteCond %{SERVER_PORT} !443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
Related
I have a problem with my website at online.net .
I want to force http to use https, but I failed.
In .htacess it didn't do anything when I use th following
RewriteEngine On
RewriteCond %{HTTP_HOST} ^my-website\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://my-website.com/$1 [R,L]
And I get an internal server Error when I try
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
or
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
thanks for any help !
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.
I need to edit my .htaccess so the following happens:
theeatalianjob.com -> https://www.theeatalianjob.com
www.theeatalianjob.com -> https://www.theeatalianjob.com
http://www.theeatalianjob.com -> https://www.theeatalianjob.com
the following:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
only adds the https:// in front of the HTTP_HOST how do I write a if statement that adds www. if missing?
Thank you for your help.
Your answer will do 2 things:
Add www if missing
Redirect http to https
So if URL is http://domain.com then there will be two redirects and that is bad for SEO and for user experience also.
You can use a single rule to do both redirects like this:
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
I think I have found the solution to my own question but feel free to suggest more elegant ones...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I am using this code for SSL migration:
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The problem that I am facing is that it is working is that the redirection is not working for most of the folders and URLs but in a few cases it is working and that is what is baffling me.
If the code was correct, it should work for every URL on the site instead of a few or it shouldn't work at all. When I remove the first re-write condition in the .htaccess, the site works just fine.
This is the error that I am getting:
https/www.mysite.com:443/some-folder/xyz.html
Can anybody help?
Thanks in advance.
try this...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I created a .htaccess file that does two things: redirects http to https and also www. to non-www. Here is the code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.profstream.com [NC]
RewriteRule ^(.*)$ https://profstream.com/$1 [L,R=301]
This works fine in Chrome, Safari, and Opera but for some reason when I type profstream.com/sandbox/login.php for example in Firefox it redirects to https://profstream.com/https://www.profstream.com/sandbox/login.php. What am I doing wrong here?
I think you are missing [L] and also [QSA], try this:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]
L is to leave, otherwise you will use the rules after this.
QSA is to add the query string of the URL.
The second part should be this I think:
RewriteCond %{HTTP_HOST} ^www.profstream.com [NC]
RewriteRule (.*) https://profstream.com%{REQUEST_URI} [QSA,L]
Don't know about the RewriteBase /, is that needed?
And if you want both to happen, perhaps you should reverse the order
RewriteCond %{HTTP_HOST} ^www.profstream.com [NC]
RewriteRule (.*) https://profstream.com%{REQUEST_URI} [QSA,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]