LiteSpeed

Add security headers with .htaccess on LiteSpeed (HSTS, CSP, X-Frame-Options)

Add HTTP security headers such as HSTS, X-Content-Type-Options, X-Frame-Options, Referrer-Policy and Content-Security-Policy to a site on LiteSpeed hosting with .htaccess.

IntermediatecPanel hosting with LiteSpeed2 min read

Security headers tell browsers how to treat your site: always use HTTPS, do not allow framing by other sites, do not guess file types. They are easy to add on LiteSpeed because it supports Apache's Header directive in .htaccess.

Before you start

  • A valid SSL certificate and HTTPS working (see AutoSSL and forcing HTTPS).
  • Access to public_html/.htaccess via File Manager (show hidden files) or FTP, and a backup copy of it.

Add these lines near the top of .htaccess:

<IfModule mod_headers.c>
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 Permissions-Policy "geolocation=(), microphone=(), camera=()"
</IfModule>
HeaderWhat it does
X-Content-Type-OptionsStops browsers guessing file types, blocking some injection tricks
X-Frame-OptionsPrevents other sites from framing your pages (clickjacking)
Referrer-PolicyLimits what URL information is sent to other sites
Permissions-PolicyDisables browser features your site does not use

HSTS: force HTTPS in the browser

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

Warning: With HSTS, browsers refuse plain HTTP for the whole max-age period. Make sure every subdomain has working SSL before adding includeSubDomains. Start with a short max-age, such as 300, and raise it after testing.

Content-Security-Policy (advanced)

CSP controls which sources may load scripts, styles and images. It is powerful but easy to get wrong. Start in report-only mode:

Header always set Content-Security-Policy-Report-Only "default-src 'self'; img-src 'self' data: https:; script-src 'self' 'unsafe-inline' https:; style-src 'self' 'unsafe-inline' https:"

Watch the browser console for violations, adjust, and switch to the enforcing Content-Security-Policy header only when nothing legitimate is blocked.

Test the headers

  1. Open the site, press F12, go to Network, reload and click the page request.
  2. Check the response headers list.
  3. Or run curl -I https://example.com from a terminal.

Caching note

Cached pages keep the headers they were stored with. After changing headers, purge LiteSpeed Cache (see LiteSpeed Web Cache Manager).

Troubleshooting

500 error after editing

A typo in the directives. Restore the backup and add lines one at a time (see .htaccess on LiteSpeed).

Site embedded elsewhere stopped working

X-Frame-Options blocks framing by other domains. Use a CSP frame-ancestors rule that allows the specific domain instead.

Frequently asked questions

Do security headers improve SEO?

Not directly. They protect visitors and are checked by security scanners; HTTPS itself is a ranking signal.

Can a WordPress plugin add these instead?

Yes, several plugins do. Use one method only, so headers are not sent twice with conflicting values.

Is X-XSS-Protection still needed?

No. Modern browsers ignore it; Content-Security-Policy is the current approach.

How do I check my headers online?

Free header-checking tools grade your site and list missing headers. Use them after each change to confirm the result.

Do headers apply to addon domains?

Only if the rules are in that domain's own .htaccess file or a parent folder the domain's document root sits in.

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.