-
-
Save nurtext/b6ac07ac7d8c372bc8eb to your computer and use it in GitHub Desktop.
# Let apache know we're behind a SSL reverse proxy | |
SetEnvIf X-Forwarded-Proto "https" HTTPS=on | |
# Redirect to HTTPS | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
RewriteCond %{HTTPS} !=on | |
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC] | |
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
</IFModule> |
For future Googlers, I found this also useful if you have WordPress running behind AWS ALB and the ALB terminates the TLS certificate (e.g. using ACM).
In this case, the WordPress ECS container, Lightsail instsance or EC2 instance (depending on how you run it), is forwarded traffic on port 80 and WordPress has no information that it's running on HTTPs. The only indication is the fact that the ALB passes the X-Forwarded-Proto=https
header, but WordPress doesn't care about that. Its is_ssl()
built-in function only cares about $_SERVER['HTTPS']='on';
being set. The first line in this Gist does just that. Sets the latter if the former is present.
@Dzhuneyt
you genius hhh:
https://developer.wordpress.org/reference/functions/is_ssl/
i have a nginx that reverse proxy wordpress by https
the wordpress is running by an docker with apache2 inside
but now it redirect between http and https, how to turn off redirect?
is can be a couple of reasons you need to be more specific.
Do you use Nginx? cPanel? Plesk? Engintron on cPanel?
I can tell you this code is effective for people who have NGINX and reverse proxy.
and I don't gonna lie if you have cPanel has the big chance this code is not recommended anymore.
cPanel design himself (APACHE as well) with new features with an interface (like windows not work on DOS anymore and when you compile it you actually need to do it from the interface).
if you work on the cloud, ssh, and individual WordPress standalone is a little different.
@crapthings
if you use cPanel is be easier to help you, btw good to know for you:
https://support.cpanel.net/hc/en-us
if you have cPanel (even from the hosting is no matter)
connect to the link they are able to help you,
if you have something also like Plesk, cPanel Engintron, stuff like this, more than here I will try help you.
any solution for nginx ?