Securing your WordPress folders is crucial to safeguarding your website from unauthorized access and potential attacks. In this guide, we’ll walk you through essential steps to enhance the security of your WordPress directories using .htaccess rules and other methods.
wp-config.php
wp-admin
Directory.htaccess
Filewp-includes
Folderwp-content
Directoryreadme.html
and license.txt
Fileswp-config.php
FileThe wp-config.php
file contains sensitive information like database credentials. Prevent direct access to this file by adding the following to your .htaccess
file:
<files wp-config.php> order allow,deny deny from all </files>
Directory browsing allows visitors to see the contents of your directories, which could expose sensitive information. Disable directory browsing by adding this line to your .htaccess
file:
Options -Indexes
wp-admin
DirectoryLimit access to the wp-admin
directory by IP address to enhance security. Add the following to your .htaccess
file in the wp-admin
directory:
<Limit GET POST> order deny,allow deny from all allow from xx.xx.xx.xx </Limit>
Replace xx.xx.xx.xx
with your IP address. You can add multiple allow from
lines for additional IPs.
.htaccess
FileEnsure that your .htaccess
file itself is not accessible. Add the following to your .htaccess
file:
<files .htaccess> order allow,deny deny from all </files>
wp-includes
FolderThe wp-includes
folder should not be accessible directly. Add the following to your .htaccess
file:
# Block the include-only files. <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^wp-admin/includes/ - [F,L] RewriteRule !^wp-includes/ - [S=3] RewriteRule ^wp-includes/[^/]+\.php$ - [F,L] RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L] RewriteRule ^wp-includes/theme-compat/ - [F,L] </IfModule>
The uploads directory should only contain media files. Disable PHP execution in this directory by creating an .htaccess
file in the wp-content/uploads
directory with the following content:
<Files *.php> deny from all </Files>
XML-RPC can be a security vulnerability. Disable it if you do not need it by adding the following to your .htaccess
file:
<Files xmlrpc.php> order deny,allow deny from all </Files>
wp-content
DirectoryOnly allow access to specific file types in the wp-content
directory by adding the following to your .htaccess
file in the wp-content
directory:
Order deny,allow Deny from all <Files ~ "\.(xml|css|js|jpe?g|png|gif|woff|woff2|ttf|svg|eot)$"> Allow from all </Files>
readme.html
and license.txt
FilesThese files can provide attackers with information about your WordPress version. Add the following to your .htaccess
file:
<FilesMatch "^(readme|license)\.(txt|html)$"> order deny,allow deny from all </FilesMatch>
Consider using security plugins such as Wordfence, Sucuri, or iThemes Security to enhance the security of your WordPress installation. These plugins offer features like firewall protection, malware scanning, and login security.
By implementing these measures, you can significantly improve the security of your WordPress folders and reduce the risk of unauthorized access and attacks. Always remember to keep your WordPress core, themes, and plugins updated to the latest versions to benefit from security patches and improvements.
By following this guide, you’ll fortify your WordPress site against common threats and keep your data secure. Happy securing!
JSON (JavaScript Object Notation) is a lightweight data-interchange format widely used in web development. At…
AJAX (Asynchronous JavaScript and XML) is a powerful technique used in modern web development that…
Introduction After successfully optimizing your website for speed, it's essential to maintain and build upon…
Creating a file upload feature with a circular progress bar involves multiple steps. You'll need…
Integrating WP Rocket with AWS CloudFront CDN helps to optimize and deliver your website content…
Securing phpMyAdmin is crucial to prevent unauthorized access and protect your databases. Here's a guide…