Add security headers: HSTS, CSP, X-Frame-Options and more

Copy-and-paste header settings that protect visitors from clickjacking, downgrade and content-injection attacks.

Updated 8 November 20262 min read2 views0 found this helpful
Applies toLiteSpeed logocPanel logo
On this page

Security headers are short instructions your server sends with every page. They cost nothing and close common attack routes.

HeaderWhat it does
Strict-Transport-Security (HSTS)Tells browsers to always use HTTPS
X-Content-Type-OptionsStops browsers guessing file types
X-Frame-Options / frame-ancestorsStops other sites framing yours (clickjacking)
Content-Security-PolicyLimits where scripts, styles and images may load from
Referrer-PolicyControls how much of your URL is shared with other sites

Apache and LiteSpeed (.htaccess)

Add to public_html/.htaccess:

<IfModule mod_headers.c>
  Header always set Strict-Transport-Security "max-age=31536000"
  Header always set X-Content-Type-Options "nosniff"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  Header always set Content-Security-Policy-Report-Only "default-src 'self' https: data: 'unsafe-inline'"
  Header unset X-Powered-By
</IfModule>

Nginx

add_header Strict-Transport-Security "max-age=31536000" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
fastcgi_hide_header X-Powered-By;

Content Security Policy, gently

A strict CSP can break chat widgets, analytics or payment buttons. Start with Content-Security-Policy-Report-Only as above, open your site with the browser console showing (F12) and note what would be blocked. Once the list is clean, rename the header to Content-Security-Policy.

Hide software versions

Headers such as X-Powered-By: PHP/8.1.2 tell attackers what to target. In cPanel open Software → MultiPHP INI Editor and set expose_php to Off.

#security headers#HSTS#CSP#.htaccess

Was this article helpful?

Your vote helps us write better guides.

Keep reading

Related articles

Still stuck?

Talk to our support team

Open a ticket

Best for anything technical. Every reply is tracked.

Submit a ticket

Call our Nairobi team

+254 726 872 512 · +254 722 917 455

Call now

Message us

Send a question and we'll reply by email or phone.

Contact support
Launch today

Powering Your Online Success!

Domain, hosting, email and SSL from one local team — set up in minutes and backed by people you can call.

  • Free SSL
  • Free migration
  • 99.9% uptime
  • 24/7 expert support

Start with your domain

Check availability, then add hosting in the same order.

Prefer to talk? Call +254 726 872 512