On a direct Apache setup, checking `%{HTTPS}` may suffice. However, behind Cloudflare, a Plesk NGINX proxy, or a load balancer, Apache sees the connection as HTTP while the visitor is using HTTPS. In this case, enforcing HTTPS using only `%{HTTPS}` creates an infinite redirect loop, and the trusted protocol header from the proxy must be used instead.
301 Moved Permanently
ERR_TOO_MANY_REDIRECTS
Location: https://example.com/
X-Forwarded-Proto: https
Cloudflare Flexible SSLOn a direct Apache setup, checking `%{HTTPS}` may suffice. However, behind Cloudflare, a Plesk NGINX proxy, or a load balancer, Apache sees the connection as HTTP while the visitor is using HTTPS. In this case, enforcing HTTPS using only `%{HTTPS}` creates an infinite redirect loop, and the trusted protocol header from the proxy must be used instead.
Do not expect a `.htaccess` result without reserving the Apache, LiteSpeed, Plesk proxy or NGINX-only structure.
Back up the current file with the date; Find the directive and line in the Apache/LiteSpeed error log.
Do not change redirect, rewrite, header and access rules all at the same time.
Measure the status, Location, Content-Type and redirect number with curl and check the cache layers separately.
Do not use Cloudflare Flexible SSL with the origin forced HTTPS rule without control.
Meaning: The browser entered a loop between two or more URLs.
Possible cause: Double HTTPS rule, application redirect, or proxy detection.
Meaning: Cloudflare connects to visitor with HTTPS, to origin with HTTP.
Possible cause: Origin forced HTTPS rule.
Meaning: The rule does not match or the `.htaccess` is not being read.
Possible cause: AllowOverride, rule order or CDN page rule.
Meaning: Canonical host and protocol produce separate redirects.
Possible cause: Two independent rules.
Meaning: The certificate challenge URL was blocked by the application or a redirect.
Possible cause: No exception for `.well-known/acme-challenge`.
Meaning: The Home/Site URL and the proxy HTTPS detection are incompatible.
Possible cause: Database URL or server variable.
Meaning: The browser or CDN is caching the permanent redirect.
Possible cause: Previous incorrect 301.
Meaning: The browser is locally upgrading to HTTPS.
Possible cause: HSTS cache.
No records matching this expression were found.
for u in http://example.com https://example.com http://www.example.com https://www.example.com; do echo "--- $u"; curl -sIL --max-redirs 10 "$u" | grep -iE '^HTTP|^location:'; doneShows the redirect chain of HTTP/HTTPS and www variations.
curl -sSI -H 'X-Forwarded-Proto: https' http://127.0.0.1 -H 'Host: example.com' | grep -iE '^HTTP|^location:'Tests the origin's response to the proxy HTTPS header.
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -subject -issuer -datesShows the certificate's domain and date information.
grep -RniE 'HTTPS|X-Forwarded-Proto|HTTP_HOST|SERVER_PORT|R=301|redirect' . --include='.htaccess' --include='*.php' | head -n 120Finds redirects in both `.htaccess` and the application.
curl -sSI https://example.com | grep -iE '^server:|^cf-ray:|^cf-cache-status:|^location:'Shows Cloudflare and redirect headers.
curl -sS -o /dev/null -w 'HTTP:%{http_code} Final:%{url_effective}\n' -L http://example.com/.well-known/acme-challenge/eka-testTest ACME path redirect and access behavior.
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]RewriteCond %{HTTPS} !=on
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]RewriteCond %{HTTPS} !=on
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]RewriteRule ^ index.php [L]RewriteRule ^\.well-known/acme-challenge/ - [L]
RewriteRule ^ index.php [L]If the origin terminates TLS directly, the HTTPS server variable can be used.
The origin learns the real visitor protocol from the trusted proxy header.
The application URL setting and the panel's Force HTTPS option may conflict with `.htaccess`.
No. NGINX does not read `.htaccess` files. The rule must be translated to a `server` or `location` configuration.
Usually not; Apache evaluates the `.htaccess` file on each request. However, a reload or restart is required for VirtualHost, module, or AllowOverride changes.
A dated backup of the existing file should be taken, the active document root verified, and the change tested on staging or during low-traffic periods.
In cPanel it is usually inside `public_html`, in Plesk inside `httpdocs`; addon domains and subdomains may have a different document root.
LiteSpeed supports most rules through Apache compatibility; some module and handler behaviors may differ.
Full directive and line record in Apache/LiteSpeed error log. The file should be restored according to the log instead of being deleted randomly.
Domain should not be added directly without verifying domain, document root, proxy, WordPress, and server structure. Examples should be adapted and tested.
We examine redirection, rewrite, CORS, access and 500 errors with logs in cPanel, Plesk, LiteSpeed, WordPress, custom PHP and WISECP structures.