HTTPS Redirect Setup in 1C-Bitrix
Redirecting from HTTP to HTTPS is a task that inexperienced developers often implement in multiple places simultaneously: in .htaccess, in init.php, and in Bitrix settings. The result is redirect chains that slow down page loading and confuse search engine crawlers.
The Right Place for Redirects
The redirect should exist in exactly one place. The preferred location is at the web server level, before PHP is invoked.
Nginx:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
Apache (.htaccess):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If the site is behind Cloudflare or another reverse proxy — configure the redirect in the CDN control panel; an additional server-level redirect is not needed (otherwise a redirect loop will occur).
www to non-www Redirect (and Vice Versa)
Choose a canonical domain and configure the redirect. In Bitrix, also specify the canonical domain under Settings → Sites → [site] — this affects how absolute URLs are generated in components.
In SEO settings (Content → SEO → Settings), enable the <canonical> tag — Bitrix will automatically insert the correct domain.
HSTS — Enforcing HTTPS at the Browser Level
Once HTTPS is stable, add the HSTS header in nginx:
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
Start with a short max-age (3600), confirm everything works, then increase it to 31536000. HSTS with preload and registration in browser preload lists is the next level and requires a separate procedure.
Verifying the Redirect Chain
curl -I -L http://www.example.com/ 2>&1 | grep -E "HTTP/|Location:"
Acceptable chain: a maximum of one 301. Two or more — there is a problem.
Real-World Case
A corporate website had redirects configured in .htaccess (www to non-www + HTTP→HTTPS), in init.php (an additional $_SERVER['HTTPS'] check), and in nginx. The total chain was 3 redirects. PageSpeed Insights flagged this as a critical issue. Solution: removed redirects from .htaccess and init.php, kept only the nginx config. Time to first byte improved by 150–300 ms.
Delivery Time
HTTPS redirect setup and verification — 1–2 hours.







