Support

Admin Tools

#41517 This Page Isn't Redirecting Properly

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
5.2.3
PHP version
8.2
Admin Tools version
7.6.2

Latest post by nicholas on Friday, 24 January 2025 09:47 CST

neo314

Hi,

I have moved from a CentOS v7.9.2009 STANDARD virtuozzo using cPanel to a AlmaLinux release 8.10 (Cerulean Leopard)using CWP.

On the CWP server, the htaccess code below cause the error that "This Page Isn't Redirecting Properly".

##### HTTP to HTTPS redirection
## Since you have enabled HSTS the first redirection rule will instruct the browser to visit the HTTPS version of your
## site. This prevents unsafe redirections through HTTP.
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://mydomain.com%{REQUEST_URI} [L,R=301]

I have to comment it out. I assume this is part of a difference in server configuration which is already forwarding to HTTPS, but since the htaccess code is described as, "This prevents unsafe redirections through HTTP", I thought I should ask if you know why this might be happening. Is the server doing a redirect that is less safe, and if so, how do I tell?

Lastly, after moving to a different server, should I rerun the configuration wizard, or do I need to disable an option in the htaccess maker to eliminate this issue? Is the setting involved, "HSTS Header (for HTTPS-only sites)"?

nicholas
Akeeba Staff
Manager

Is it possible that your site is behind a TLS termination proxy, or a different kind of reverse proxy (including NginX configured as a reverse proxy, Varnish, a public CDN, etc)?

In this case, the web server on your site won't possibly know if the site is being accessed over HTTPS unless the proxy sets the X-Forwarded-Proto HTTP header to https. This is not an HTTP header you'll read about in any version of the HTTP protocol specification; it's a de facto standard. It's also very easy for someone less experienced to set up a reverse proxy forgetting to enable this header.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

neo314

I am somewhat new to NGINX. It is running on my new VPS as a reverse proxy. I do not see where to look at the configuration, and so I asked about the header and this was the reply I got so far: "Generally, it is set dynamically to whatever URI scheme is used. So the forwarder proto is http if http://, and https if https://, it can be explicitly set to https though." So, I take it from your message, this means that it doesn't know and therefore keeps forwarding to itself.

Do you have a recommendation? I could reconfigure NGINX, but I just migrated to this server, so I'm still feeling my way around. If I wanted to skip this in the .htaccess file, what should I uncheck? Is it the "HSTS Header (for HTTPS-only sites)" setting?

nicholas
Akeeba Staff
Manager

It's a bit beyond the scope of our support, but I can give you some general pointers and information which will help you set up your server.

First, read Wikipedia's very good overview of how a reverse proxy works. The simple diagram they have is something you need to internalise to successfully troubleshoot these issues.

What listens to ports 80 (HTTP) and 443 (HTTPS) on your server is NginX, not Apache. When NginX receives a request, it may serve it from its cache (that's why we use it in the first place), or by proxying the request through Apache. The latter means that NginX asks Apache to handle the request, but the result is NOT sent directly to the visitor by Apache. Instead, it is intercepted by NginX, processed as needed, with the processed result finally handed over by NginX to the visitor.

As you noticed, this means that Apache is isolated from the outside world. It does not know if the request is HTTP or HTTPS. It does not know who is the visitor making this request. It only knows what NginX tells it. If you are familiar with the way the Oracle in Delphi operated in the ancient world, that's pretty much it; NginX is the priests interfacing with the visitors, Apache is the Oracle, sitting alone in a dark room, spitting out its prophecies. All communication between the visitors and the Oracle is mediated through the priests.

This means that regardless of whether the visitor is using HTTP or HTTPS, Apache will only ever see a plain old HTTP request coming from NginX. As a result, Apache will not set the HTTPS environment flag for HTTPS request; it doesn't know it's being used, as this is not exposed in the request itself. The solution to that is for NginX to pass the X-Fowarded-Proto HTTP header which conveys which protocol was used in the actual request: HTTP or HTTPS. This can be done by putting proxy_set_header X-Forwarded-Proto $scheme; above the proxy_pass directive in your NginX configuration file.

Another problem with this configuration is that Apache always sees the IP address NginX runs on (in your case, 127.0.0.1) as the source for all traffic. This makes blocking the IP address naughty requests come from impossible. NginX can convey the real IP address of the visitor in the X-Forwarded-For HTTP header which allows the software running under Apache (such as Joomla) to find out the real IP address of the visitor, with some extra steps. This can be done by putting proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; above the proxy_pass directive in your NginX configuration file. You MUST also go into Joomla's Global Configuration and set Behind Load Balancer to Yes which tells Joomla to use the X-Forwarded-For HTTP header to determine the visitor's IP address.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

neo314

Awesome. You're the best. Thanks.

nicholas
Akeeba Staff
Manager

You're welcome! I am happy to have been able to help you :)

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!