Era Host hosting
EraHost – Free Domain, Cheap Hosting!
Client Area
Support 24/7
Menu

How to Add Vary: Accept Header Using cPanel

3 min read
15.07.2025

If you are hosting your website on a server with cPanel, you can configure the Vary: Accept header either through the .htaccess file, using a custom PHP script, or with built-in options in cPanel (if available). Below are the steps to set up the header for your site.

cPanel Vary Accept Header
Vary: Accept — variant per Accept header (mobile vs desktop content negotiation).

For closely related caching / header topics, see Gzip and Vary: Accept-Encoding, Cache-Control: max-age — Complete Guide, and Cache-Control: max-age with public.

Option 1: Add the Vary: Accept Header via .htaccess

Log in to cPanel

Navigate to your hosting account and log in to cPanel.

Open File Manager

  • Under the Files section, click File Manager.
  • Go to the root directory of your website (e.g., /public_html/).

Edit the .htaccess File

  • Locate the .htaccess file. If it does not exist, create one by clicking + File and naming it .htaccess.
  • Right-click the file and select Edit.

Add the Following Code

<IfModule mod_headers.c>

    Header append Vary: Accept

</IfModule>

Save Changes

Click Save Changes in the editor and close the file.

Test Configuration

Verify the header is applied by using browser developer tools or a cURL command:

curl -I https://yourdomain.com
cPanel Hosting
Full control over your website
  • Convenient
  • Simple
  • Fast
  • Free 7-day trial
cPanel Hosting

Option 2: Add the Vary: Accept Header Using PHP

Log in to cPanel and Navigate to File Manager

Edit the Index File

  • Locate your main PHP file (e.g., index.php or home.php) in the /public_html/ directory.
  • Right-click the file and select Edit.

Add the Following Code at the Top

<?php

header("Vary: Accept");



// Example content negotiation

if (strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) {

    header("Content-Type: application/json");

    echo json_encode(["message" => "This is a JSON response"]);

} else {

    header("Content-Type: text/html");

    echo "<html><body>This is an HTML response</body></html>";

}

?>

Save the File and Test the Changes

Option 3: Use cPanel Built-in Header Features

Some cPanel installations include tools for managing HTTP headers (e.g., via the Apache Handlers or Headers Modules). If your hosting provider enables this:

  1. Log in to cPanel.
  2. Go to Advanced > Apache Handlers or a similar section.
  3. Look for options to add custom headers.
  4. Add the Vary: Accept header.

Verifying the Vary: Accept Header

  1. Using cURL: Run the following command:
  2. curl -I https://yourdomain.com

    Look for:

    Vary: Accept
  3. Using Browser Developer Tools:
    • Open your browser Developer Tools (F12).
    • Go to the Network tab.
    • Reload the page and inspect the response headers.
  4. Using Online Tools: Use tools like WebPageTest or GTmetrix to verify the presence of the Vary header.

Best Practices for Vary: Accept in cPanel Hosting

  1. Use Only When Necessary: Avoid over-fragmenting caches by combining multiple Vary headers (e.g., Vary: Accept, User-Agent).
  2. Test Across Browsers: Ensure different client types (e.g., JSON API clients, mobile devices) receive the correct content.
  3. Combine with Proper Cache-Control: Use caching headers like Cache-Control and Expires for better performance.
  4. Check Compression: Ensure gzip or Brotli compression is enabled for even better results.

By following these steps, you can set up the Vary: Accept header on a cPanel server to enable content negotiation and improve caching behavior.

Frequently asked questions
Accept-Encoding handles compression (gzip/br/identity) — almost every site needs this. Accept handles content type (HTML vs JSON vs XML at the same URL) — used when serving API/page from one URL. Most sites don't need Vary: Accept; almost all need Vary: Accept-Encoding. Set Accept-Encoding unconditionally if you serve compressed responses.
`Header append Vary Accept` (or Accept-Encoding, Accept-Language, etc.). Use `append` to add to existing Vary headers; `set` to override. mod_headers must be enabled — cPanel sites usually have it. If your Header directive is ignored, AllowOverride may not include mod_headers in the parent vhost config — contact host.
Each unique Accept value creates a new cache entry. If Accept comes in many variants (rare for Accept; common for Accept-Language with 50+ locales), cache hit ratio drops. CDNs may normalize Vary'd headers — Cloudflare groups similar Accept-Language values. For shared caches you control, normalize aggressively before responding.
Some users see compressed bytes they can't decode (Accept-Encoding mismatch), or English speakers see German content (Accept-Language mismatch). Browser devtools shows the actual Cache-Control + Vary; compare to the user's Accept-* request headers. If the cached response Vary didn't match the current request's Accept-*, it's a CDN config bug. Audit Vary in origin responses and CDN's cache-key configuration.
Related articles
Gzip and Vary: Accept-Encoding Header
Specify a Vary: Accept-Encoding Header
How to Add a Vary: Accept Header Using PHP