How to set up internal protection for .htaccess
- Category : cPanel Question
- Posted on : Mar 03, 2020
- Views : 1,416
- By : HostSEO
This part is applicable only for cases when you wish to manually set up all the necessary settings and rules. All these settings can be set up automatically with secure plugins (especially BulletProof Security). We recommend using the secure plugins first and only if they fail to deliver necessary control, perform manual configuration. If you do need to make specific changes to the .htaccess file manually, kindly use the guide provided below:
.htaccess (hypertext access) is the default name of the directory-level configuration file specific for web servers running Apache.
This is a file which is modified the most often when dealing with redirects and is also often used to change file types to make them executable. It is also the one you will be using to harden your environment.
To protect it, apply a few simple rules – set low permissions and deny access.
Apply Low Permissions
The basic guidance for permissions is simple: the lower the number, the harder the access becomes. Good rule of thumb is to keep the number as low as possible where the performance or functionality is not impacted. For most users, setting it to 640 will grant the level of access that you need.
Add .HTACCESS Directives
What’s important to note here is that this only works if the attack is external. This won’t protect you from internal attacks (if an entire cPanel account is hacked, for example)
This is the .htaccess directive you can use:
#PROTECT HTACCESS
Order Allow, Deny
Deny from all
Note: This only protects the file from external access.
- Disable directory browsing
If you do not want to allow your visitors to browse through your entire directory, simply add the piece of 2 lines in your .htaccess in the root directory of your WordPress blog:
# disable directory browsing
Options All -Indexes
- wp-config file protection
Wp-config.php is important because it contains all the sensitive data and configuration of your blog and therefore, it should be locked through .htaccess. Add the code below to the .htaccess file in the root directory:
# protect wpconfig.php
order allow,deny
deny from all
The code denies access to the wp-config.php file to everyone.
- Access to wp-content directory
Wp-content contains all content for your WordPress installation. This is a very important folder and it should be secured. Users should be only able to view and access certain file types like images (jpg, gif, png), Javascript, css and XML.
Place the code below in the .htaccess file within the wp-content folder (not the root):
Order deny,allow
Deny from all
Allow from all
- wp-admin files
Wp-admin should be accessed only by you and your fellow bloggers (if any). You may use .htaccess to restrict access and allow only specific IP addresses to this directory.
If you have a static IP address and you always blog from your computer, this can be a good option for you. However, if you run a multiple user blog, then either you can opt out of it or you can allow access from a range of IPs.
Copy and paste the code below into the .htaccess in the wp-admin folder (not the root folder):
# deny access to wp admin
order deny,allow
allow from xx.xx.xx.xx # This is your static IP
deny from all
The above code will prevent the browser from accessing any file in these directories other than “xx.xx.xx.xx” which should be your static IP address.
- Prevent script injection
To protect your WordPress blog from script injection and unwanted modification of _REQUEST and/or GLOBALS, copy and paste the code below into your .htaccess in the root:
# protect from sql injection
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]
That's it!
Categories
- cPanel Question 47
- cPanel Software Management 29
- cPanel Tutorials 13
- Development 29
- Domain 13
- General 19
- Linux Helpline (Easy Guide) 156
- Marketing 47
- MySQL Question 13
- News 2
- PHP Configuration 14
- SEO 4
- SEO 42
- Server Administration 84
- SSL Installation 54
- Tips and Tricks 24
- VPS 3
- Web Hosting 44
- Website Security 22
- WHM questions 13
- WordPress 148
Subscribe Now
10,000 successful online businessmen like to have our content directly delivered to their inbox. Subscribe to our newsletter!Archive Calendar
Sat | Sun | Mon | Tue | Wed | Thu | Fri |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Recent Articles
-
Posted on : Sep 17
-
Posted on : Sep 10
-
Posted on : Aug 04
-
Posted on : Apr 01
Tags
- ts
- myisam
- vpn
- sql
- process
- kill
- tweak
- server load
- attack
- ddos mitigation
- Knowledge
- layer 7
- ddos
- webmail
- DMARC
- Development
- nginx
- seo vpn
- Hosting Security
- wireguard
- innodb
- exim
- smtp relay
- smtp
- VPS Hosting
- cpulimit
- Plesk
- Comparison
- cpu
- encryption
- WHM
- xampp
- sysstat
- optimize
- cheap vpn
- php-fpm
- mariadb
- apache
- Small Business
- Error
- Networking
- VPS
- SSD Hosting
- Link Building
- centos
- DNS
- optimization
- ubuntu