Arama Yap Mesaj Submit
Request a Callback
+90
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro
X
X

Select Your Currency

Turkish Lira $ US Dollar Euro

Contact Us

Location Halkali merkez neighborhood fatih st ozgur apt no 46 , Kucukcekmece , Istanbul , 34303 , TR
SSL, Proxy, and Redirect Loops

How to Redirect to HTTPS with .htaccess?

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.

Force HTTPSERR_TOO_MANY_REDIRECTSCloudflareX-Forwarded-Proto301
Apache/LiteSpeed Diagnostics
301 Moved Permanently
ERR_TOO_MANY_REDIRECTS
Location: https://example.com/
X-Forwarded-Proto: https
Cloudflare Flexible SSL
01Verify file and document root
02Take a backup and read the error log
03Separate server and application context
04Verify live result with curl
01
Safe technical approach

Redirecting HTTP to HTTPS How to analyze?

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.

01

Determine server type

Do not expect a `.htaccess` result without reserving the Apache, LiteSpeed, Plesk proxy or NGINX-only structure.

02

Get backup and logs

Back up the current file with the date; Find the directive and line in the Apache/LiteSpeed error log.

03

Change one rule

Do not change redirect, rewrite, header and access rules all at the same time.

04

Test from outside

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.

02
Live problem dictionary

Apache, redirect and access messages

01kritik

ERR_TOO_MANY_REDIRECTS

Meaning: The browser entered a loop between two or more URLs.

Possible cause: Double HTTPS rule, application redirect, or proxy detection.

02kritik

Cloudflare Flexible SSL loop

Meaning: Cloudflare connects to visitor with HTTPS, to origin with HTTP.

Possible cause: Origin forced HTTPS rule.

03warning

HTTPS is enabled but HTTP is not redirecting

Meaning: The rule does not match or the `.htaccess` is not being read.

Possible cause: AllowOverride, rule order or CDN page rule.

04warning

www and HTTPS are redirected in two steps

Meaning: Canonical host and protocol produce separate redirects.

Possible cause: Two independent rules.

05warning

ACME validation broken

Meaning: The certificate challenge URL was blocked by the application or a redirect.

Possible cause: No exception for `.well-known/acme-challenge`.

06warning

WordPress admin redirect loop

Meaning: The Home/Site URL and the proxy HTTPS detection are incompatible.

Possible cause: Database URL or server variable.

07warning

301 Old Cache Rule

Meaning: The browser or CDN is caching the permanent redirect.

Possible cause: Previous incorrect 301.

08bilgi

HTTP cannot be tested after HSTS

Meaning: The browser is locally upgrading to HTTPS.

Possible cause: HSTS cache.

No records matching this expression were found.

03
Copiable controls

curl, Apache log and file tests

Four URL variations

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:'; done

Shows the redirect chain of HTTP/HTTPS and www variations.

Proxy header test

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.

SSL certificate

echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -subject -issuer -dates

Shows the certificate's domain and date information.

Search redirect rules

grep -RniE 'HTTPS|X-Forwarded-Proto|HTTP_HOST|SERVER_PORT|R=301|redirect' . --include='.htaccess' --include='*.php' | head -n 120

Finds redirects in both `.htaccess` and the application.

Cloudflare indicators

curl -sSI https://example.com | grep -iE '^server:|^cf-ray:|^cf-cache-status:|^location:'

Shows Cloudflare and redirect headers.

ACME URL test

curl -sS -o /dev/null -w 'HTTP:%{http_code} Final:%{url_effective}\n' -L http://example.com/.well-known/acme-challenge/eka-test

Test ACME path redirect and access behavior.

04
Correct and incorrect structure

.htaccess rule comparisons

Direct Apache

Risky / Incorrect
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Right Approach
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]

Proxy-aware HTTPS

Risky / Incorrect
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]
Right Approach
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]

Tek canonical hedef

Risky / Incorrect
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]
Right Approach
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]

ACME exception

Risky / Incorrect
RewriteRule ^ index.php [L]
Right Approach
RewriteRule ^\.well-known/acme-challenge/ - [L]
RewriteRule ^ index.php [L]
05
Application by infrastructure

Apache, cPanel, Plesk, LiteSpeed and applications

Apache / LiteSpeed

If the origin terminates TLS directly, the HTTPS server variable can be used.

  • The certificate must cover both canonical hosts.
  • The rule must be placed before other rewrites.
  • A staging test with 302 can be performed before applying 301.

Cloudflare / Reverse Proxy

The origin learns the real visitor protocol from the trusted proxy header.

  • Choose Cloudflare Full (Strict).
  • Accept the header only from a trusted proxy.
  • Do not use double redirects on both origin and edge.

WordPress / WISECP / Plesk

The application URL setting and the panel's Force HTTPS option may conflict with `.htaccess`.

  • Check the WordPress Home/Site URL values.
  • Match the WISECP SSL and domain settings with the canonical host.
  • Manage the Plesk Preferred domain and 301 setting as a single source.
Incorrect interventions

Absolutely don't

  • Do not use Cloudflare Flexible SSL with the origin forced HTTPS rule without control.
  • Do not make a 301 permanent after seeing the first working test in the browser without measuring the redirect chain.
  • Do not use the HTTP_HOST value as an open redirect target without validation.
  • Do not enable the HSTS header before the HTTPS setup is fully verified.
Post-procedure check

Verify the solution

  • All HTTP and www variations redirect to the canonical HTTPS URL in a single hop.
  • The redirect chain has no loops or more than 10 hops.
  • ACME, admin and API paths working as expected.
  • The WordPress/WISECP URL setting and the `.htaccess` target match.
06
Internal SEO content set

Related .htaccess solutions

07
primary sources

Apache, WordPress and panel documentation

08
Frequently asked questions

Redirecting HTTP to HTTPS Curiosities about

Does the HTTP to HTTPS redirect rule work on NGINX?

No. NGINX does not read `.htaccess` files. The rule must be translated to a `server` or `location` configuration.

Is Apache restart required for .htaccess changes?

Usually not; Apache evaluates the `.htaccess` file on each request. However, a reload or restart is required for VirtualHost, module, or AllowOverride changes.

What should be done before editing the file?

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.

Where is the file located in Plesk with cPanel?

In cPanel it is usually inside `public_html`, in Plesk inside `httpdocs`; addon domains and subdomains may have a different document root.

Does LiteSpeed support `.htaccess` rules?

LiteSpeed supports most rules through Apache compatibility; some module and handler behaviors may differ.

Where should I look first in case of a 500 error?

Full directive and line record in Apache/LiteSpeed error log. The file should be restored according to the log instead of being deleted randomly.

Can these codes be added directly to the live site?

Domain should not be added directly without verifying domain, document root, proxy, WordPress, and server structure. Examples should be adapted and tested.

EKA SOFTWARE AND INFORMATION SYSTEMS

Let's edit .htaccess and Apache rules without making the site inaccessible

We examine redirection, rewrite, CORS, access and 500 errors with logs in cPanel, Plesk, LiteSpeed, WordPress, custom PHP and WISECP structures.

Get Server SupportWhatsApp
Top