Question
How to manage X-Frame-Options through .htaccess for your website
Answer
CPANEL_WARN: Please note cPanel is unable to assist with making these modifications.
- Access your WHM server as the
rootuser and navigate to Home / Server Configuration / Terminal -
Run the following commands.
CPANEL_INFO: Replacing
cpanelusernameanddomain.tldwith your cPanel user and domain. Additionally, the "include" in "include.conf" can be changed, but the files are loaded in alphabetical order.# mkdir -p /etc/apache2/conf.d/userdata/ssl/2_4/cpanelusername/domain.tld/
mkdir -p /etc/apache2/conf.d/userdata/std/2_4/cpanelusername/domain.tld/
touch /etc/apache2/conf.d/userdata/ssl/2_4/cpanelusername/domain.tld/include.conf
touch /etc/apache2/conf.d/userdata/std/2_4/cpanelusername/domain.tld/include.conf -
Edit the newly created files and add the following.
CONFIG_TEXT: <ifModule mod_headers.c>
Header set Strict-Transport-Security "max-age=31536000" env=HTTPS
Header always set X-Frame-Options "sameorigin"
</ifModule> -
Rebuild the Apache configuration to add the includes with this command:
# /usr/local/cpanel/scripts/rebuildhttpdconf
-
Restart Apache so it reads the new configuration.
# /usr/local/cpanel/scripts/restartsrv_httpd
- Access your cPanel account.
- Locate and open File Manager.
- Select the folder your
.htaccessis in, usuallypublic_html. - Select the .htaccess file and edit the file.
-
Add the following.
CONFIG_TEXT: <ifModule mod_headers.c>
Header set Strict-Transport-Security "max-age=31536000" env=HTTPS
Header always set X-Frame-Options "deny"
Header setifempty Referrer-Policy: same-origin
Header set X-XSS-Protection "1; mode=block"
Header set X-Permitted-Cross-Domain-Policies "none"
Header set Referrer-Policy "no-referrer"
Header set X-Content-Type-Options: nosniff
</ifModule> - Save your changes.
Confirm this is working by running this command, replacing domain.tld with your domain.
# curl -s --head -D- https://domain.tld/ | egrep -i 'strict|location|powered|sameorigin|deny'
Additional Resources
How to use Apache includes to add configuration directives to a specific domain's virtualhost
Comments
0 comments
Article is closed for comments.