{"id":4193,"date":"2022-07-13T07:20:13","date_gmt":"2022-07-13T14:20:13","guid":{"rendered":"https:\/\/SUMMALAI.COM\/?p=4193"},"modified":"2022-07-13T07:20:15","modified_gmt":"2022-07-13T14:20:15","slug":"how-to-add-http-security-headers-in-wordpress","status":"publish","type":"post","link":"https:\/\/SUMMALAI.COM\/?p=4193","title":{"rendered":"How to Add HTTP Security Headers in WordPress"},"content":{"rendered":"\n<p>by&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/author\/wpbeginner\/\">Editorial Staff<\/a><a href=\"mailto:?subject=Your%20friend%20has%20shared%20an%20article%20you%20with%20you.&amp;body=How%20to%20Add%20HTTP%20Security%20Headers%20in%20WordPress%20(Beginner%E2%80%99s%20Guide)%20https%3A%2F%2Fwww.wpbeginner.com%2Fbeginners-guide%2Fhow-to-add-http-security-headers-in-wordpress%2F\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><\/p>\n\n\n\n<p>Do you want to add HTTP security headers in WordPress?<\/p>\n\n\n\n<p>HTTP security headers allow you to add an extra layer of security to your WordPress website. They can help block common malicious activity from affecting your website performance.<\/p>\n\n\n\n<p>In this beginner\u2019s guide, we\u2019ll show you how to easily add HTTP security headers in WordPress.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">What are HTTP Security Headers?<\/h4>\n\n\n\n<p>HTTP security headers are a security measure that allows your website\u2019s server to prevent some common security threats before it affects your website.<\/p>\n\n\n\n<p>Basically, when a user visits your website, your web server sends an HTTP header response back to their browser. This response tells browsers about error codes, cache control, and other statuses.<\/p>\n\n\n\n<p>The normal header response issues a status called HTTP 200. After which your website loads in the user\u2019s browser. However, if your website is having difficulty then your web server may send a different HTTP header.<\/p>\n\n\n\n<p>For example, it may send a&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/wp-tutorials\/how-to-fix-the-internal-server-error-in-wordpress\/\">500 internal server error<\/a>, or a&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/wp-tutorials\/how-to-fix-wordpress-posts-returning-404-error\/\">not found 404 error<\/a>&nbsp;code.<\/p>\n\n\n\n<p>HTTP security headers are a subset of these headers and are used to prevent websites from common threats like click-jacking, cross-site scripting,&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/wp-tutorials\/how-to-protect-your-wordpress-site-from-brute-force-attacks-step-by-step\/\">brute force attacks<\/a>, and more.<\/p>\n\n\n\n<p>Let\u2019s have a quick glance at what HTTP security headers look like and what they do to protect your website.<\/p>\n\n\n\n<p><strong>HTTP Strict Transport Security (HSTS)<\/strong><\/p>\n\n\n\n<p>HTTP Strict Transport Security (HSTS) header tells web browsers that your website uses HTTPs and should not be loaded using insecure protocol like HTTP.<\/p>\n\n\n\n<p>If you have moved your&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/wp-tutorials\/how-to-add-ssl-and-https-in-wordpress\/\">WordPress website from HTTP to HTTPs<\/a>, then this security header allows you to stop browsers from loading your website on HTTP.<\/p>\n\n\n\n<p><strong>X-XSS Protection<\/strong><\/p>\n\n\n\n<p>X-XSS Protection header allows you to block cross-site scripting from loading on your&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/guides\/\">WordPress website<\/a>.<\/p>\n\n\n\n<p><strong>X-Frame-Options<\/strong><\/p>\n\n\n\n<p>X-Frame-Options security header prevents cross-domain iframes or click-jacking.<\/p>\n\n\n\n<p><strong>X-Content-Type-Options<\/strong><\/p>\n\n\n\n<p>X-Content-Type-Options blocks content mime-type sniffing.<\/p>\n\n\n\n<p>That being said, let\u2019s take a look at how to easily add HTTP security headers in WordPress.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Adding HTTP Security Headers in WordPress<\/h4>\n\n\n\n<p>HTTP security headers work best when they are set at the web server level (i.e your&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/wordpress-hosting\/\">WordPress hosting<\/a>&nbsp;account). This allows them to be triggered early on during a typical HTTP request and provides maximum benefit.<\/p>\n\n\n\n<p>They work even better if you are using a DNS-level&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/plugins\/best-wordpress-firewall-plugins-compared\/\">website application firewall<\/a>&nbsp;like Sucuri or Cloudflare. We\u2019ll show you each method, and you can choose one that works best for you.<\/p>\n\n\n\n<p>Here are quick links to different methods, you can jump to the one that suits you.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"securityheaders-sucuri\">1. Adding HTTP Security Headers in WordPress using Sucuri<\/h4>\n\n\n\n<p><a href=\"https:\/\/www.wpbeginner.com\/refer\/sucuri\/\" rel=\"noreferrer noopener\" target=\"_blank\">Sucuri<\/a>&nbsp;is the&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/plugins\/best-wordpress-security-plugins-compared\/\">best WordPress security plugin<\/a>&nbsp;on the market. If you are using their website firewall service too, then you can set HTTP security headers without writing any code.<\/p>\n\n\n\n<p>First, you will need to sign up for a&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/refer\/sucuri\/\" rel=\"noreferrer noopener\" target=\"_blank\">Sucuri<\/a>&nbsp;account. It is a paid service that comes with a sever level website firewall, security plugin, CDN, and malware removal guarantee.<\/p>\n\n\n\n<p>During sign up, you will answer simple questions, and Sucuri documentation will help you set up the website application firewall on your website.<\/p>\n\n\n\n<p>After signing up, you need to install and activate the free&nbsp;<a href=\"https:\/\/wordpress.org\/plugins\/sucuri-scanner\/\" rel=\"noreferrer noopener\" target=\"_blank\">Sucuri plugin<\/a>. For more details, see our step by step guide on&nbsp;<a href=\"http:\/\/www.wpbeginner.com\/beginners-guide\/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners\/\">how to install a WordPress plugin<\/a>.<\/p>\n\n\n\n<p>Upon activation, go to&nbsp;<strong>Sucuri Security \u00bb Firewall (WAF)<\/strong>&nbsp;page and enter your Firewall API key. You can find this information under your account on Sucuri website.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.wpbeginner.com\/wp-content\/uploads\/2021\/03\/sucuri-waf-api.png\" alt=\"Sucuri WAF API key\" class=\"wp-image-91334\" title=\"Sucuri WAF API key\"\/><\/figure>\n\n\n\n<p>Click on the Save button to store your changes.<\/p>\n\n\n\n<p>Next, you need to switch to your&nbsp;<a rel=\"noreferrer noopener\" target=\"_blank\" href=\"https:\/\/www.wpbeginner.com\/refer\/sucuri\/\">Sucuri<\/a>&nbsp;account dashboard. From here, click on the Settings menu on top and then switch to the Security tab.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.wpbeginner.com\/wp-content\/uploads\/2021\/03\/sucuri-security-headers.png\" alt=\"Setting HTTP security headers in Sucuri \" class=\"wp-image-91335\" title=\"Setting HTTP security headers in Sucuri\"\/><\/figure>\n\n\n\n<p>From here you can choose three sets of rules. The default protection, HSTS, and HSTS Full. You will see which HTTP security headers will be applied for each set of rules.<\/p>\n\n\n\n<p>Click on the \u2018Save Changes in The Additional Headers\u2019 button to apply your changes.<\/p>\n\n\n\n<p>That\u2019s all, Sucuri will now add your selected HTTP security headers in WordPress. Since it is a DNS level WAF, your website traffic is protected from hackers even before they reach your website.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"securityheaders-cloudflare\">2. Adding HTTP Security Headers in WordPress using Cloudflare<\/h4>\n\n\n\n<p>Cloudflare offers a basic free website firewall and CDN service. It lacks advanced security features in their free plan, so you will need to upgrade to their Pro plan which are more expensive.<\/p>\n\n\n\n<p>To add Cloudflare on your site, see our tutorial on how to&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/wp-tutorials\/how-to-setup-cloudflare-free-cdn-in-wordpress\/\">add Cloudflare free CDN in WordPress<\/a>.<\/p>\n\n\n\n<p>Once Cloudflare is active on your website, go to the SSL\/TLS page under your Cloudflare account dashboard and then switch to the Edge Certificates tab.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.wpbeginner.com\/wp-content\/uploads\/2021\/03\/cloudflare-header-security.png\" alt=\"Setting up HTTPS security headers in Cloudflare\" class=\"wp-image-91400\" title=\"Setting up HTTPS security headers in Cloudflare\"\/><\/figure>\n\n\n\n<p>Now, scroll down to the HTTP Strict Transport Security (HSTS) section and click on the \u2018Enable HSTS\u2019 button.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.wpbeginner.com\/wp-content\/uploads\/2021\/03\/enablehsts-cloudflare.png\" alt=\"Enable HSTS on Cloudflare\" class=\"wp-image-91401\" title=\"Enable HSTS on Cloudflare\"\/><\/figure>\n\n\n\n<p>This will bring up a popup with instructions telling you that you must have HTTPS enabled on your&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/start-a-wordpress-blog\/\">WordPress blog<\/a>&nbsp;before using this feature. Click on the Next button to continue, and you will see the options to add HTTP security headers.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.wpbeginner.com\/wp-content\/uploads\/2021\/03\/enablehttpsheaders.png\" alt=\"Enable HTTPS security headers in Cloudflare\" class=\"wp-image-91402\" title=\"Enable HTTPS security headers in Cloudflare\"\/><\/figure>\n\n\n\n<p>From here, you can enable HSTS, no-sniff header, apply HSTS to subdomains (if they are using HTTPS), and preload HSTS.<\/p>\n\n\n\n<p>This method provides basic protection using HTTP security headers. However, it does not let you add X-Frame-Options and Cloudflare doesn\u2019t have a user interface to do that.<\/p>\n\n\n\n<p>You can still do that by creating a script using the Workers feature. However, creating an HTTPS security header script may cause unexpected issues for beginners which is why we wouldn\u2019t recommend it.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"securityheaders-htaccess\">3. Adding HTTP Security Headers in WordPress using .htaccess<\/h4>\n\n\n\n<p>This method allows you to set the HTTP security headers in WordPress at the server level.<\/p>\n\n\n\n<p>It requires you to edit the&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/glossary\/htaccess\/\">.htaccess file<\/a>&nbsp;on your website. It is a server configuration file used by the most commonly used Apache webserver software.<\/p>\n\n\n\n<p>Simply connect to your website&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/showcase\/6-best-ftp-clients-for-wordpress-users\/\">using an FTP client<\/a>, or the file manager app in your hosting control panel. In the root folder of your website, you need to locate the .htaccess file and edit it.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.wpbeginner.com\/wp-content\/uploads\/2021\/03\/edit-htaccess.jpg\" alt=\"Edit the .htaccess file in WordPress\" class=\"wp-image-91405\" title=\"Edit the .htaccess file in WordPress\"\/><\/figure>\n\n\n\n<p>This will open the file in a plain text editor. At the bottom of the file, you can add the code to add HTTPS security headers to your WordPress website.<\/p>\n\n\n\n<p>You can use the following sample code as a starting point, it sets the most commonly used HTTPs security headers with optimal settings:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1234567<\/td><td><code>&lt;ifModule mod_headers.c&gt;<\/code><code>Header set Strict-Transport-Security <\/code><code>\"max-age=31536000\"<\/code><code>env=HTTPS<\/code><code>Header set X-XSS-Protection <\/code><code>\"1; mode=block\"<\/code><code>Header set X-Content-Type-Options nosniff<\/code><code>Header set X-Frame-Options DENY<\/code><code>Header set Referrer-Policy: no-referrer-when-downgrade<\/code><code>&lt;\/ifModule&gt;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Don\u2019t forget to save your changes and visit your website to make sure that everything is working as expected.<\/p>\n\n\n\n<p><strong>Note:<\/strong>&nbsp;Incorrect headers or conflicts in .htaccess file may trigger&nbsp;<a href=\"https:\/\/www.wpbeginner.com\/wp-tutorials\/how-to-fix-the-internal-server-error-in-wordpress\/\">500 Internal server error<\/a>&nbsp;on most web hosts.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"securityheaders-plugin\">4. Adding HTTP Security Headers in WordPress using Plugin<\/h4>\n\n\n\n<p>This method is a little less effective as it relies on a WordPress plugin to modify the headers. However, it is also the easiest way to add HTTP security headers to your WordPress website.<\/p>\n\n\n\n<p>First, you need to install and activate the&nbsp;<a href=\"https:\/\/wordpress.org\/plugins\/redirection\/\" rel=\"noreferrer noopener\" target=\"_blank\">Redirection<\/a>&nbsp;plugin. For more details, see our step by step guide on&nbsp;<a href=\"http:\/\/www.wpbeginner.com\/beginners-guide\/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners\/\">how to install a WordPress plugin<\/a>.<\/p>\n\n\n\n<p>Upon activation, the plugin will show a set up wizard that you can just follow along to set up the plugin. After that, go to&nbsp;<strong>Tools \u00bb Redirection<\/strong>&nbsp;page and switch to the \u2018Site\u2019 tab.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.wpbeginner.com\/wp-content\/uploads\/2021\/03\/redirectionsitetab.png\" alt=\"Site settings in Redirection plugin\" class=\"wp-image-91406\" title=\"Site settings in Redirection plugin\"\/><\/figure>\n\n\n\n<p>Next, you need to scroll down to the bottom of the page to the HTTP Headers section and click on the \u2018Add Header\u2019 button. From the drop-down menu, you need to select \u2018Add Security Presets\u2019 option.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.wpbeginner.com\/wp-content\/uploads\/2021\/03\/addinghttpheaders-redirection.png\" alt=\"Adding header presets using Redirection\" class=\"wp-image-91407\" title=\"Adding header presets using Redirection\"\/><\/figure>\n\n\n\n<p>After that, you will need to click on it again to add those options. Now, you will see a preset list of HTTP security headers appear in the table.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.wpbeginner.com\/wp-content\/uploads\/2021\/03\/commonhttpsecurityheaders.png\" alt=\"HTTP security header presets\" class=\"wp-image-91408\" title=\"HTTP security header presets\"\/><\/figure>\n\n\n\n<p>These headers are optimized for security, you can review them and change them if needed. Once you are done, don\u2019t forget to click on the Update button to save your changes.<\/p>\n\n\n\n<p>You can now visit your website to make sure that everything is working fine.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"securityheaders-testing\">How to Check HTTP Security Headers for a Website<\/h4>\n\n\n\n<p>Now that, you have added HTTP Security headers to your website. You can test your configuration using the free&nbsp;<a href=\"https:\/\/securityheaders.com\/\" rel=\"noreferrer noopener\" target=\"_blank\">Security Headers<\/a>&nbsp;tool. Simply enter your website URL and click on the Scan button.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.wpbeginner.com\/wp-content\/uploads\/2021\/03\/testsecurityheaders.png\" alt=\"Checking your WordPress security headers\" class=\"wp-image-91410\" title=\"Checking your WordPress security headers\"\/><\/figure>\n\n\n\n<p>It will then check HTTP security headers for your website and will show you a report. The tool would generate a so-called grade label which you can ignore as most websites would get a B or C score at best without affecting user experience.<\/p>\n\n\n\n<p>It will show you which HTTP security headers are sent by your website and which security headers are not included. If the security headers that you wanted to set are listed there, then you are done.<\/p>\n\n\n\n<p>Ref: <a href=\"https:\/\/www.wpbeginner.com\/beginners-guide\/how-to-add-http-security-headers-in-wordpress\/#securityheaders-htaccess\">How to Add HTTP Security Headers in WordPress (Beginner&#8217;s Guide) (wpbeginner.com)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>by&nbsp;Editorial Staff Do you want to add HTTP security headers in WordPress? HTTP security headers allow you to add an extra layer of security to your WordPress website. They can help block common malicious activity from affecting your website performance. In this beginner\u2019s guide, we\u2019ll show you how to easily add HTTP security headers in <a class=\"read-more\" href=\"https:\/\/SUMMALAI.COM\/?p=4193\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[104,5,178],"tags":[1205],"class_list":["post-4193","post","type-post","status-publish","format-standard","hentry","category-apache","category-linux","category-wordpress","tag-add-http-security-headers-in-wordpress"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/4193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4193"}],"version-history":[{"count":2,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/4193\/revisions"}],"predecessor-version":[{"id":4239,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/4193\/revisions\/4239"}],"wp:attachment":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}