I have a few servers behind a Load Balancer running Apache with PHP we're finding that people can't hold an SSL session. You can access any page on the site using https by adding https:// to the URL but when you click a link even though that link will show https you get redirected back to a standard http page.
On the Load Balancer listener page I have it set up as:
HTTP 80 to HTTP 80
TCP (SSL) 443 to TCP 80
I've tried non-TCP and using https and I've tried 443 to 443 but that throws a Server 503 error (server overload). I've added a *:443 VirtualHost on the servers but that didn't work.
I also even tried a:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://www.mydomain.com/$1 [R=301,L]
as an .htaccess rule. But users are still being redirected back to HTTP when navigating.
Any ideas?
I would guess the right track is having HTTPS 443 to HTTP 80, not TCP. Can you provide more details about what happens when you configure it this way?
Related
I am trying to redirect http trafic from http to https on ec2 behind a network load balancer using htaccess
# aws rule for http to https
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
Above code does not work because network loadbalancer does not add x-forwarded header.
i have a service that is running over docker under port 8081 ( on ubuntu 20 ) and i can access it under http:
my-domain.local:8081/myservice
i have installed apache2 as a reverse proxy in front of it and it works also fine and i can access the service under https (443) and my ssl certificates:
https://my-domain.local/myservice --- works fine
but its still accessible under http also and i dont want it. I want that it will be accessible only under https:
http://my-domain.local:8081/myservice ----> https://my-domain.local/myservice
it is maybe a very simple situation but i am new to apache. Thanks for your help
That is what i have tried:
<VirtualHost *:8081>
ServerName my-domain.local
Redirect "/" "https://my-domain.local/myservice"
</VirtualHost>
i have also tried something with the use of RewriteRule in the .htacces like below:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
but none of the works.
i expect, if someone calls the url under http in browser it will be redirected to https:
http://my-domain.local:8081/myservice ----> https://my-domain.local/myservice
I have setup a load balancer which accepts https connections from users. The compute engines are then connected to load balancer using http connection.
I have written the following .htaccess file in the root folder:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Now, the problem is, the compute engine is always connected via http link (to the load balancer) and not https.
Thus, the .htaccess file always consider the connection to be http and not https even if the url starts with https. So, it goes in an infinite loop trying to send the user to https even when the url is https.
What should be done to redirect http to https in this case.
Thanks.
You should check the X-Forwarded-Proto http header. It is set by the load balancer and will have the value http or https.
This took so long for me to find the answer to! Thank you so much #Lennert!
user#host-vm:/opt/bitnami/apps/wordpress/htdocs# head -4 /opt/bitnami/apps/wordpress/conf/htaccess.conf
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
For those who are using php, I've been looking for a simple way to make my project redirect any page to https in Google Cloud, and I found a simple solution. All you have to do is to add this code at the top of your php page. It has to be at the top, the F̲i̲r̲s̲t̲ L̲i̲n̲e̲ of code in your header:
<?php
if ($_SERVER['HTTPS'] == 'off') {
header("Location: https://www.YOUR_SITE.com".$_SERVER['REQUEST_URI']);
die();
}
?>
Got a vServer and plesk installed on it (Apache backend, Nginx reverse proxy), plesk is listening on port 8443.
I use the hostname as a domain for easier accesss and SSL certificate domain. So I would like to redirect ALL traffic to specific one:
What I got so far is this rule
return 301 https://www.DOMAIN.com:8443/;
which leads everything to the Plesk Panel URL but if someone is using this
https://DOMAIN.com:8443
he won't be redirected to
https://www.DOMAIN.com:8443
and the SSL certificate won't work (domain based). How can I force every traffic (http and https with the ports 80 and 8443) to
https://www.DOMAIN.com:8443
Thanks in advance
You could HTACCESS to do it:
The Code
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI}:8443 [R=301,L]
What this does is check if the user is trying to access the site without using www and if so redirect to www on the specific port that you wanted.
If you already have your port 80 traffic redirecting to port 8443 and you just want to redirect the rule for www, what I have listed above will work. You can also have mod rewrite redirect based on the port used.
It would look like this:
The Code
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{SERVER_PORT} ^80$
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI}:8443 [R=301,L]
You would just need to make sure that each virtual host you are using has the mod rewrite rule in place. You might have to create a virtual host for the extra ports you want to use. The only thing these virtual hosts would have is the redirect rule. Otherwise you might get 404 errors.
I'm working on a website locally that contains https links, so when I click on one of these links it takes me to https://localhost/... which doesn't exist as there is no SSL certificate installed.
Is there anything I can add to .htaccess that checks if I'm on localhost and if so redirects https to http? The .htaccess file is used in both local development and production on our server so anything I add mustn't affect the live website.
Nope.
Reason is any rules you put in your htaccess file will only get applied once the request has been made, which means it'll only get applied once the https://localhost/ request is made. If there's nothing listening to the HTTPS port (443) on localhost, then the rules will never get applied.
If port 443 is listening for requests on localhost, but it's just a matter of lacking an SSL certificate, the rules still won't get applied until after the SSL handshake is performed, which means, you're still going to get the security warning about your certificate.
That being said, the rules you'd want if you had apache listening to port 443 and have a certificate installed is this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R]