MODRACXKENNETH D'SILVA

← Archive & Insights

Enforcing HSTS for Secure SEO and Trust

Discover how implementing HTTP Strict Transport Security (HSTS) safeguards your site, boosts SEO, and builds customer trust for Magento and Shopify stores.

By Kenneth D'Silva (MODRACX)

Introduction

Search engines reward sites that serve every request over HTTPS. Beyond the obvious encryption, the HTTP Strict Transport Security (HSTS) header tells browsers to always use HTTPS for your domain, eliminating protocol‑downgrade attacks and improving perceived security—an important ranking signal in Google’s algorithm.

1. What Is HSTS?

Element Description
Header Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
max‑age Length (in seconds) browsers should enforce HTTPS. Typical value: 1 year (31,536,000 s).
includeSubDomains Extends policy to all sub‑domains (e.g., shop.example.com).
preload Opt‑in to the HSTS Preload List maintained by browsers, guaranteeing HTTPS from the first request.

2. Why HSTS Matters for SEO

  • Google’s HTTPS Requirement – All URLs must be served over HTTPS to appear in search results.
  • Reduced Mixed‑Content Errors – Eliminates warnings that cause page‑load penalties.
  • Improved Trust Signals – Browsers show a lock icon, increasing click‑through rates from SERPs.
  • Core Web Vitals Boost – Eliminates extra redirects, shaving milliseconds off TTFB and LCP.

3.1 Nginx

server {
    listen 443 ssl http2;
    server_name example.com www.example.com;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
    # optional: add HSTS for subdomains only after a period of stable HTTPS
    # add_header Strict-Transport-Security "max-age=31536000; preload" always;
}
  • Reload: sudo nginx -s reload.
  • Verify with curl: curl -I https://example.com | grep strict-transport-security.

3.2 Apache (mod_headers)

<IfModule mod_headers.c>
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</IfModule>
  • Restart Apache: sudo systemctl restart httpd.

3.3 Magento 2

  1. Enable HTTPS in Stores > Configuration > Web > Secure (set Use Secure URLs in Frontend/Backend to Yes).
  2. Add the header via nginx or apache (see above) — Magento itself does not set HSTS.
  3. Optionally, create a custom module that adds the header through $response->setHeader for dynamic flexibility.

3.4 Shopify

Shopify serves all stores over HTTPS by default, but you can add HSTS via the Shopify CDN only through Shopify’s own infrastructure. To guarantee the header, request Shopify Plus support to enable HSTS preload on your custom domain.

4. Preloading Your Domain

  1. Submit to the HSTS Preload List.
  2. Ensure all sub‑domains serve valid TLS certificates and no HTTP endpoints.
  3. Use includeSubDomains and preload in the header.
  4. After acceptance, browsers will hard‑code HTTPS for your domain, eliminating the first‑request redirect.

5. SEO Checklist for HSTS

6. Common Pitfalls & Mitigations

Pitfall Symptom Fix
Premature preload – domain not fully HTTPS ready. Browsers block site; users see security error. Remove preload until all sub‑domains are HTTPS, then resubmit.
Long max‑age with mis‑config – accidental HTTP downgrade for months. Users stuck on insecure version. Test thoroughly on a staging sub‑domain before applying to prod.
Mixed‑content after enable – some assets still loaded via HTTP. Chrome console shows Mixed Content warnings. Update all asset URLs to HTTPS or serve them via CDN with TLS.

7. Performance Validation

Tool Metric Expected Result
curl -I Header presence strict-transport-security shown.
Lighthouse Redirects Zero redirect warnings.
WebPageTest TTFB Slightly lower (no extra 301/302).
Search Console Security Issues None reported.

Conclusion & Call‑to‑Action

Deploying HSTS is a low‑effort, high‑reward step that hardens security, removes unnecessary redirects, and signals trust to both users and search engines. Ready to lock down your storefront with HSTS and boost SEO? Click the “Start a project” button on the MODRACX portfolio and let Kenneth D’Silva implement a rock‑solid security header for you.


Kenneth D’Silva – Security & SEO engineer, MODRACX