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.

On this page
Security headers are short instructions your server sends with every page. They cost nothing and close common attack routes.
| Header | What it does |
|---|---|
| Strict-Transport-Security (HSTS) | Tells browsers to always use HTTPS |
| X-Content-Type-Options | Stops browsers guessing file types |
| X-Frame-Options / frame-ancestors | Stops other sites framing yours (clickjacking) |
| Content-Security-Policy | Limits where scripts, styles and images may load from |
| Referrer-Policy | Controls 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.
Was this article helpful?
Your vote helps us write better guides.
