{"id":155577,"date":"2016-05-20T14:00:26","date_gmt":"2016-05-20T14:00:26","guid":{"rendered":"https:\/\/premium.wpmudev.org\/blog\/?p=155577"},"modified":"2022-03-21T23:57:00","modified_gmt":"2022-03-21T23:57:00","slug":"htaccess","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/htaccess\/","title":{"rendered":"A Comprehensive Guide to Editing .htaccess for WordPress Security"},"content":{"rendered":"<p>The .htaccess file in your WordPress install is a powerful configuration file that you can use to override the settings on your web server to improve your site\u2019s security and performance.<\/p>\n<p>Short for \u201cHypertext Access,\u201d you can edit the file and with the right commands, you can enable\/disable extra functionality and features to protect your site from spammers, hackers and other threats.<\/p>\n<p>Some of these features include basic redirects, locking outside access to particular files, or more advanced functions such as content password protection or preventing image hotlinking.<\/p>\n<p>So let\u2019s take an in-depth look at how you can manipulate your .htaccess file to boost your security.<\/p>\n<p>In this post, we&#8217;ll cover the following:<\/p>\n<ul>\n<li><a href=\"#where-is-htaccess-located\">Where&#8217;s the <em>.htaccess File <\/em>Located?<\/a><\/li>\n<li><a href=\"#backup-wp-site\">Backing Up Your WordPress Site<\/a><\/li>\n<li><a href=\"#change-htaccess\">Making Changes to <em>.htaccess<\/em> Files<\/a>\n<ul>\n<li><a href=\"#create-htaccess\">Creating an <em>.htaccess<\/em> File<\/a><\/li>\n<li><a href=\"#where-to-add-htaccess\">Where to Add Your Changes<\/a><\/li>\n<li><a href=\"#edit-htaccess\">Editing Your <em>.htaccess<\/em> File<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#secure-htaccess\">.htaccess Security Tips<\/a>\n<ol>\n<li><a href=\"#protect-files\">Protecting Important Files<\/a><\/li>\n<li><a href=\"#restrict-admin\">Restrict Access to the Admin<\/a><\/li>\n<li><a href=\"#prevent-directory-browsing\">Prevent Directory Browsing<\/a><\/li>\n<li><a href=\"#restrict-php-access\">Restrict Access to PHP Files<\/a><\/li>\n<li><a href=\"#restrict-php-execution\">Restrict PHP File Execution<\/a><\/li>\n<li><a href=\"#protect-against-script-injections\">Protect Your Site Against Script Injections<\/a><\/li>\n<li><a href=\"#secure-wpincludes\">Securing the\u00a0<i>wp-includes<\/i> Directory<\/a><\/li>\n<li><a href=\"#prevent-username-enumeration\">Prevent Username Enumeration<\/a><\/li>\n<li><a href=\"#require-ssl\">Require SSL<\/a><\/li>\n<li><a href=\"#prevent-image-hot-linking\">Prevent Image Hot Linking<\/a><\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<h2 id=\"where-is-htaccess-located\">What&#8217;s <em>.htaccess<\/em>\u00a0Got to Do with It?<\/h2>\n<p>The <em>.htaccess<\/em>\u00a0file is located in the root of your site (or Multisite network). The period in front of the file name means it&#8217;s a hidden file and you won&#8217;t be able to see it when browsing your files unless you show all\u00a0hidden\u00a0files on your computer.<\/p>\n<p>In WordPress, the file is used\u00a0for facilitating pretty permalinks and\u00a0is automatically\u00a0created when this\u00a0option is enabled. There&#8217;s a lot more you can do with .<em>htaccess<\/em>, though, such as <a href=\"https:\/\/wpmudev.com\/blog\/creating-301-redirects-wordpress\/\" target=\"_blank\" rel=\"noopener\">adding 301 redirects<\/a> or including rules to block unauthorized visitors.<\/p>\n<p>If you&#8217;re already well-versed in the <em>.htaccess<\/em>\u00a0file and you&#8217;re ready to make some changes, go ahead and skip down to see the list, (<a href=\"https:\/\/wpmudev.com\/project\/snapshot\/\" target=\"_blank\">don&#8217;t forget to backup your site first!<\/a>)<\/p>\n<h2 id=\"backup-wp-site\">I Pity the Fool Who Doesn&#8217;t Backup<\/h2>\n<p>The .<em>htaccess<\/em>\u00a0file can be a finicky one to work with because a single syntax error could break your entire site. That being said, if you&#8217;re prepared, this kind of worse case scenario doesn&#8217;t have to spell a death sentence for your site. In fact, far from it.<\/p>\n<p>Backing up your site before you make any changes can act as a fail safe so you can quickly restore your files\u00a0and be on your way as if nothing ever happened. Well, close enough to that, anyway.<\/p>\n<p>The absolute least you should do is download a copy of your <em>.htaccess<\/em>\u00a0file on your computer so you can replace it if a mistake is made.\u00a0You can download a copy of your <em>.htaccess<\/em>\u00a0file in cPanel by going to <strong>Files &gt; File Manager<\/strong> after logging in. If you&#8217;re prompted with a pop-up, select the <strong>Show Hidden Files<\/strong> checkbox, then click Go.<\/p>\n<p>Alternatively, you can click <strong>Settings<\/strong> on the top right of the <strong>File Manager<\/strong> and click the <strong>Show Hidden Files<\/strong> checkbox, then click the <strong>Save<\/strong> button.<\/p>\n<div  class=\"wpdui-pic-regular  \">\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-735x735 size-735x735\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2016\/05\/cpanel-show-hidden-files.png\" alt=\"The settings pop-up in the file manager.\" width=\"735\" height=\"400\" \/><figcaption class=\"wp-caption-text\">The <em>.htaccess<\/em> file is hidden by default.<\/figcaption><\/figure>\n<\/div>\n<p>You should be able to go to the\u00a0root of your site now and find the .<em>htaccess<\/em>\u00a0file. Click on it once on the list, then click the <strong>Download<\/strong> button in the navigation. Save it to your computer. If you need to restore it, you can click the <strong>Upload<\/strong> button on the top of the page.<\/p>\n<p>Select the <strong>Overwrite existing files<\/strong> checkbox, then click the <strong>Select File<\/strong> button to search for and open the backup of your <em>.htaccess<\/em> file.<\/p>\n<div  class=\"wpdui-pic-large   \" >\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-1364x1364 size-1364x1364\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2016\/05\/cpanel-upload-overwrite-file.png\" alt=\"The file upload page.\" width=\"1364\" height=\"400\" \/><figcaption class=\"wp-caption-text\">You can overwrite existing files in cPanel to restore the <em>.htaccess<\/em> file.<\/figcaption><\/figure>\n<\/div>\n<p>Once you have opened the file, it should upload and you can click the <strong>Go Back<\/strong> link at the bottom of the page to return to your <strong>File Manager<\/strong>. Once that&#8217;s done, it means your <em>.htaccess<\/em> file has been \u00a0restored.<\/p>\n<p>Note: If you are <a href=\"https:\/\/wpmudev.com\/hosting\/\" target=\"_blank\" rel=\"noopener\">hosting with WPMU DEV<\/a>, you can perform the same operation as above by accessing the <a href=\"https:\/\/wpmudev.com\/blog\/web-file-management-hosting\/\" target=\"_blank\" rel=\"noopener\">File Manager<\/a> feature inside your Hub.<\/p>\n<p>For details on how to create a full backup of your site, check out some of our other posts below:<\/p>\n<ul>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/backup-with-snapshot\/\" target=\"_blank\" rel=\"noopener\">How to Backup Your WordPress Website (and Multisite) Using Snapshot<\/a><\/li>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/multisite-backup-solutions\/\" target=\"_blank\" rel=\"noopener\">4 Top WordPress Multisite Backup Solutions Tested and Reviewed<\/a><\/li>\n<li><a href=\"https:\/\/wpmudev.com\/blog\/free-quality-backup-plugins\/\" target=\"_blank\" rel=\"noopener\">11 Best Free Quality Backup Plugins for Protecting Your WordPress Site<\/a><\/li>\n<\/ul>\n<h2 id=\"change-htaccess\">Going Through Changes<\/h2>\n<h3 id=\"create-htaccess\">Creating an <em>.htaccess<\/em> File<\/h3>\n<p>Depending on your install, you may not have an <em>.htaccess<\/em> file so before you can think about editing\u00a0it, you may need to create one. You can either use your favorite text editor to create one or do it\u00a0directly in cPanel.<\/p>\n<p>Create and upload a new file and name it .<em>htaccess<\/em>, or click the <strong>File<\/strong> button at the top left of the <strong>File Manager<\/strong> in cPanel to create a blank file named <em>.htaccess<\/em>.<\/p>\n<p>If your server doesn&#8217;t allow you to do this, create a file called <em>htaccess.txt<\/em> instead, then rename the file to <em>.htaccess<\/em> once it&#8217;s uploaded to your site.<\/p>\n<p>Since all WordPress installs have pretty permalinks set by default since version 4.2, it&#8217;s best to side on the err of caution and include the code that&#8217;s default for <em>.htaccess<\/em> files in the newer versions of WordPress instead of creating a blank file.<\/p>\n<p>Here&#8217;s the default code you should include for single installs of WordPress:<\/p>\n<div class=\"gist\" data-gist=\"7c0c55104fae10d3536d0408a4eeea37\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/7c0c55104fae10d3536d0408a4eeea37.js?file=.htaccess\">Loading gist 7c0c55104fae10d3536d0408a4eeea37<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>For Multisite networks installed with sub-directories using version 3.5 or higher, use the following code instead:<\/p>\n<div class=\"gist\" data-gist=\"da7c56eaaeae727be5389b52055b821f\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/da7c56eaaeae727be5389b52055b821f.js?file=.htaccess\">Loading gist da7c56eaaeae727be5389b52055b821f<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>If your Multisite is installed with sub-domains and the version you&#8217;re using is 3.5 or higher, use the code below instead of the options above:<\/p>\n<div class=\"gist\" data-gist=\"811e3a2d828471aea73ae402cf0e8590\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/811e3a2d828471aea73ae402cf0e8590.js?file=.htaccess\">Loading gist 811e3a2d828471aea73ae402cf0e8590<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>For any other versions of WordPress, check out the <a href=\"http:\/\/codex.wordpress.org\/htaccess\" rel=\"noopener\" target=\"_blank\">WordPress Codex&#8217;s <em>.htaccess<\/em> page<\/a> for details on the code you should include in your file.<\/p>\n<p>When you&#8217;re creating a new .<em>htaccess<\/em> file, it&#8217;s important that you set a file permission of 644 to protect it from potential attacks. For details on how to do this, check out one of our other posts\u00a0<a href=\"https:\/\/wpmudev.com\/blog\/understanding-file-permissions\/\" target=\"_blank\" rel=\"noopener\">Understanding File Permissions and Using Them to Secure Your Site<\/a>.<\/p>\n<h3 id=\"where-to-add-htaccess\">Where to Add Your Changes<\/h3>\n<p>When you&#8217;re editing your file, it&#8217;s important to note that lines beginning with a hashtag are comments and aren&#8217;t included in the <em>.htaccess<\/em> rule. When you&#8217;re adding rules, it&#8217;s crucial that you include them either above or below the default WordPress rule explained above.<\/p>\n<p>You shouldn&#8217;t add or edit anything between the lines <code># BEGIN WordPress<\/code> and <code># END WordPress<\/code>. For Multisite networks, the same principle applies, although, there aren&#8217;t any comments at the beginning and end as there are for single installs.<\/p>\n<p>If you were to make any changes, it&#8217;s likely that it would be overwritten so it&#8217;s best to just stay out of its way and let WordPress do its thing.<\/p>\n<p>Generally speaking, adding rules below the default WordPress lines keeps things more organized and\u00a0adds a bit of clarity as to what your edits are as opposed to WordPress&#8217; code. It may also be helpful to add your own comments to any additions you make to further organize your <em>.htaccess<\/em> file.<\/p>\n<p>At the end of the day, it&#8217;s up to you and what would work best for your needs.<\/p>\n<p>There&#8217;s also a handy <a href=\"http:\/\/winginx.com\/en\/htaccess\" rel=\"noopener\" target=\"_blank\"><em>.htaccess<\/em> to Nginx converter<\/a> you can use to adjust the tips later on in the article for use with \u2013 you guessed it \u2013 Nginx.<\/p>\n<h3 id=\"edit-htaccess\">Editing\u00a0Your <em>.htaccess<\/em> File<\/h3>\n<p>There are many ways you can choose to edit your <em>.htaccess<\/em> file and one of them is to do it directly in cPanel. Most people find this to be the easiest method, but I won&#8217;t stop you from using the method that&#8217;s your favorite.<\/p>\n<p>No matter which method you choose, it may be helpful to note that you refreshing your site after you save an edit to your file will allow you to check whether your edits break your site. If they do, you can immediately restore the file and try again. If everything works as it should, then you&#8217;re good to go and you can continue making edits.<\/p>\n<p>Once you&#8217;re logged into cPanel, go to <strong>Files &gt; File Manager<\/strong> and choose to show hidden files as described earlier. Go to the root of your site and click once on your <em>.htaccess<\/em> file that&#8217;s listed. Click <strong>Edit<\/strong> in the navigation at the top of the page to make your changes.<\/p>\n<p>Don&#8217;t forget to click <strong>Save<\/strong> before exiting so your changes aren&#8217;t lost.<\/p>\n<p>You can also choose to edit files using FTP. You can find the details on how to do this by checking out\u00a0<a href=\"https:\/\/wpmudev.com\/blog\/ftp-wordpress\/\" target=\"_blank\" rel=\"noopener\">How to Use FTP Properly with WordPress<\/a>.<\/p>\n<p>You can also choose to use SSH to\u00a0makes changes as well. You can check out\u00a0<a href=\"https:\/\/wpmudev.com\/blog\/terminal-command-line\/\" target=\"_blank\" rel=\"noopener\">A Quick Guide to the Terminal and Command Line Prompt for WordPress<\/a> for details on how to use an SSH client.<\/p>\n<p>SSH commands are not the same for every kind of server so consult your server type&#8217;s documentation for the commands you need to use.<\/p>\n<h2 id=\"secure-htaccess\">.htaccess Security Tips<\/h2>\n<p>Now you&#8217;re ready to tighten your site&#8217;s security with the tips below. Let&#8217;s get to it.<\/p>\n<h3 id=\"protect-files\">1. Protecting Important Files<\/h3>\n<p>One of the best edits you can make is to protect your <em>.htaccess<\/em> file along with your error logs, wp-config.php and php.ini files. Once you make the following change, attempts to access these files are denied.<\/p>\n<div class=\"gist\" data-gist=\"d12b3eb2dd2bbf2890c88b0ae826b74a\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/d12b3eb2dd2bbf2890c88b0ae826b74a.js?file=.htaccess\">Loading gist d12b3eb2dd2bbf2890c88b0ae826b74a<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Be sure to check your files and see if you have one named <em>php.ini<\/em> because you may not. Instead, you may have one called <em>php5.ini<\/em>. If this is the case, replace <code>php.ini<\/code> with <code>php5.ini<\/code> in the above rule.<\/p>\n<h3 id=\"restrict-admin\">2. Restrict Access to the Admin<\/h3>\n<p>You can also restrict access to the admin dashboard and login page by adding the rules below if you use a static IP address:<\/p>\n<div class=\"gist\" data-gist=\"c20841915e9dff00a1d08f2b508367e8\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/c20841915e9dff00a1d08f2b508367e8.js?file=.htaccess\">Loading gist c20841915e9dff00a1d08f2b508367e8<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>The first two lines redirect unauthorized IP addresses to your 404 error page. This also helps you resolve any redirect loops so your site doesn&#8217;t look like it&#8217;s down. Just be sure to edit both instances of <code>\/path-to-your-site\/<\/code> to the real path of your site.<\/p>\n<p>Also, replace <code>IP Address One<\/code>, <code>IP Address Two<\/code> and <code>IP Address Three<\/code> with the actual IP addresses you want to have access to these pages. If you only want to add one address, omit lines nine and 10. You can also repeat line 10 as many times as you would like and replace each<\/p>\n<p>You can also repeat line 10 as many times as you would like and replace each\u00a0<code>IP Address Three<\/code>\u00a0with the real IP address you want to whitelist.<\/p>\n<p>If you or any of your other users have dynamic IP addresses, a Multisite network or multiple users in your network that need to log in, you can use the following rule instead:<\/p>\n<div class=\"gist\" data-gist=\"5d4b869da5e8d8813f3ebe05c5bb6830\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/5d4b869da5e8d8813f3ebe05c5bb6830.js?file=.htaccess\">Loading gist 5d4b869da5e8d8813f3ebe05c5bb6830<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Don&#8217;t forget to switch <code>\/path-to-your-site\/<\/code> in lines one and two to the real path to your site as well as change <code>your-site.com<\/code> with your actual domain.<\/p>\n<p>Many hackers use bots to try and access the admin dashboard or to log in externally. By adding this to your <em>.htaccess<\/em> file, you&#8217;re only letting people who manually enter your site into their browser&#8217;s address bar to have access to these pages.<\/p>\n<p>While it won&#8217;t block hackers that try to manually guess your users&#8217; login details, in most cases, it still makes a huge difference and significantly lowers the amount of brute force attacks you receive.<\/p>\n<h3 id=\"prevent-directory-browsing\">3. Prevent Directory Browsing<\/h3>\n<p>It&#8217;s possible for visitors to see a list of your site&#8217;s directories in the front-end if they enter in your domain and then a directory into their browser&#8217;s address bar. Since WordPress has a set file structure, nothing&#8217;s currently stopping someone from visiting <em>your-site.com\/wp-content-uploads\/<\/em> and seeing a list of your folder and files.<\/p>\n<p>This is definitely not what you want because it&#8217;s that much easier for a hacker to hack into an important file in your site if they can literally see the target file in plain sight and don&#8217;t have to guess where the file is located.<\/p>\n<blockquote><p>It&#8217;s the equivalent of hiding a spare key to your place in a super clever and secretive place, but then posting a note right on your door letting everyone who visits know where your spare key is hidden.<\/p><\/blockquote>\n<p>Adding this line to your .<em>htaccess<\/em> file prevents directory browsing so hackers have a more difficult time figuring you out.<\/p>\n<div class=\"gist\" data-gist=\"72640ace06190d9ab0b3ee31e82025a3\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/72640ace06190d9ab0b3ee31e82025a3.js?file=.htaccess\">Loading gist 72640ace06190d9ab0b3ee31e82025a3<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<h3 id=\"restrict-php-access\">4. Restrict Access to PHP Files<\/h3>\n<p>Similarly, providing direct access to your PHP files is a big no-no. The harder you make it for hackers to be able to find your important files, the better and since PHP files can be used to inject malicious code to further infect your site, it&#8217;s incredibly important that you protect your PHP files.<\/p>\n<p>You can add the following lines from <a href=\"http:\/\/www.acunetix.com\/websitesecurity\/wordpress-security-top-tips-secure-wordpress-application\/\" rel=\"noopener\" target=\"_blank\">Acunetix<\/a> to block direct access to your plugin and theme&#8217;s PHP files from unauthorized users:<\/p>\n<div class=\"gist\" data-gist=\"b4fe37954c9ceb7479565c43802bd948\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/b4fe37954c9ceb7479565c43802bd948.js?file=.htaccess\">Loading gist b4fe37954c9ceb7479565c43802bd948<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<h3 id=\"restrict-php-execution\">5. Restrict PHP File Execution<\/h3>\n<p>While we&#8217;re on the subject, you may as well also prevent unauthorized execution of PHP files so in the event that a hack does break into your site, they won&#8217;t be able to upload their own PHP file with malicious code and have it actually work.<\/p>\n<p>This means you can prevent <a href=\"https:\/\/wpmudev.com\/blog\/removing-backdoor-exploits\/\" target=\"_blank\" rel=\"noopener\">backdoor exploits<\/a> from actually working. While you would still have to find and remove the file, the more obstacles you make for a hacker, the less likely it is that your site can be infected beyond repair.<\/p>\n<p>Since most hackers upload backdoors to your \/wp-content\/uploads\/ folder, blocking the execution of any PHP files there can be a huge help.<\/p>\n<p>Add the code below to <a href=\"http:\/\/www.acunetix.com\/websitesecurity\/wordpress-security-top-tips-secure-wordpress-application\/\" rel=\"noopener\" target=\"_blank\">restrict the execution of PHP files<\/a> added to the uploads folder:<\/p>\n<div class=\"gist\" data-gist=\"a7372675bb45ec2d801f08435d751941\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/a7372675bb45ec2d801f08435d751941.js?file=.htaccess\">Loading gist a7372675bb45ec2d801f08435d751941<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<h3 id=\"protect-against-php-injections\">6. Protect Your Site Against Script Injections<\/h3>\n<p>You&#8217;re on a serious roll now so why not also prevent injections of malicious code into your PHP files? <a href=\"http:\/\/www.wprecipes.com\/protect-your-wordpress-blog-using-htaccess\" rel=\"noopener\" target=\"_blank\">WP Recipes posted a way to prevent script injections<\/a>.<\/p>\n<p>Many hackers try to change the WordPress GLOBALS and _REQUEST variables in an attempt to inject malicious code. You can add the following to your .<em>htaccess<\/em> file to prevent this change from being accepted:<\/p>\n<div class=\"gist\" data-gist=\"ec424a9d05b11e5c366e04f3a5b0ad71\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/ec424a9d05b11e5c366e04f3a5b0ad71.js?file=.htaccess\">Loading gist ec424a9d05b11e5c366e04f3a5b0ad71<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<h3 id=\"secure-wpincludes\">7.\u00a0 Securing the\u00a0<i>wp-includes<\/i> Directory<\/h3>\n<p>Your wp-includes directory is home to so many of your important files. By blocking all unauthorized access to it, you can protect those all important files from being tampered with by hackers.<\/p>\n<p><a href=\"http:\/\/www.wpexplorer.com\/htaccess-wordpress-security\/\" rel=\"noopener\" target=\"_blank\">WP Explorer<\/a> has a great addition to include to prevent hackers from accessing your wp-includes folder:<\/p>\n<div class=\"gist\" data-gist=\"90642d45b55b87a466f1d361848130fd\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/90642d45b55b87a466f1d361848130fd.js?file=.htaccess\">Loading gist 90642d45b55b87a466f1d361848130fd<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<h3 id=\"prevent-username-enumeration\">8. Prevent Username Enumeration<\/h3>\n<p>When a visitor enters <em>your-site.com\/?author=1<\/em> into their address bar, they&#8217;re directed to the author&#8217;s page that has a user ID of one. The author&#8217;s page includes the actual username associated with the user ID.<\/p>\n<p>The visitor would easily be able to get all the usernames of all the users of your site if they have any posts associated with their account. This process is called username enumeration.<\/p>\n<p>If a hacker is able to easily get a hold of your username, it&#8217;s one less thing they need to guess. In fact, the only other detail they need to guess is your password.<\/p>\n<p>While knowing the username associated with an account isn&#8217;t going to add much value for a hacker if the user uses a strong password, it can still be beneficial to prevent username enumeration since the more obstacles you an make for a hacker, the less likely it is that they can actually infiltrate your site.<\/p>\n<p>Here&#8217;s how you can <a href=\"http:\/\/www.acunetix.com\/websitesecurity\/wordpress-security-top-tips-secure-wordpress-application\/\" rel=\"noopener\" target=\"_blank\">prevent username enumeration<\/a> by adding the following to your <em>.htaccess<\/em> file:<\/p>\n<div class=\"gist\" data-gist=\"285ed1597bad4107294e436db73026e7\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/285ed1597bad4107294e436db73026e7.js?file=.htaccess\">Loading gist 285ed1597bad4107294e436db73026e7<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<h3 id=\"require-ssl\">9. Require SSL<\/h3>\n<p>Use the code below to force the use of an SSL certificate unless the exact\u00a0Fully Qualified Domain Name (FQDN) listed in line three is entered:<\/p>\n<div class=\"gist\" data-gist=\"4833875f2c29f89ef560b3cecf2a009b\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/4833875f2c29f89ef560b3cecf2a009b.js?file=.htaccess\">Loading gist 4833875f2c29f89ef560b3cecf2a009b<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Just don&#8217;t forget to replace <code>www.your-site.com<\/code>\u00a0on lines three and four with your actual domain name.<\/p>\n<p>It&#8217;s also worth noting that you can check out our post\u00a0<a href=\"https:\/\/wpmudev.com\/blog\/ssl-https-wordpress\/\" target=\"_blank\" rel=\"noopener\">How to Use SSL and HTTPS with WordPress<\/a> for more details on how you can force the use of SSL for your site.<\/p>\n<h3 id=\"prevent-image-hot-linking\">10.\u00a0 Prevent Image Hot Linking<\/h3>\n<p>When a visitor grabs the URL of one of your images and loads it into their site instead of uploading the image to their server, they&#8217;re stealing your bandwidth. It&#8217;s also called hot linking.<\/p>\n<p>To prevent this from happening, add this to your .htaccess file:<\/p>\n<div class=\"gist\" data-gist=\"b39a25ae601735adc30a98b25135a978\" data-gist-file=\".htaccess\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/b39a25ae601735adc30a98b25135a978.js?file=.htaccess\">Loading gist b39a25ae601735adc30a98b25135a978<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div>\n<p>Don&#8217;t forget to replace <code>your-site.com<\/code> with your actual domain in line two and replace <code>http:\/\/www.your-site.com\/hotlink.gif<\/code> in line three with the actual URL of the image you want to protect.<\/p>\n<h2>Wrapping Up<\/h2>\n<p>With these tips and rules\u00a0you can help secure your WordPress site or network and block hackers every chance you get. Don&#8217;t forget, though, that these changes are just one step towards bolstering security on your site \u2013 there&#8217;s always more you can and should do.<\/p>\n<p>Installing a security plugin such as <a href=\"https:\/\/wpmudev.com\/project\/wp-defender\/\" target=\"_blank\" rel=\"noopener\">Defender<\/a> can vastly improve the security of your site. Plus, Defender is included in a WPMU DEV membership and you can even <a href=\"https:\/\/wpmudev.com\" target=\"_blank\" rel=\"noopener\">try Defender for free<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The .htaccess file in your WordPress install is a powerful configuration file that you can use to override the settings on your web server to improve your site\u2019s security and performance. Here&#8217;s how to bend it to your will.<\/p>\n","protected":false},"author":54213,"featured_media":162936,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[557],"tags":[10810,9924],"tutorials_categories":[],"class_list":["post-155577","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-wordpress-security","tag-htaccess"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/155577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/54213"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=155577"}],"version-history":[{"count":23,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/155577\/revisions"}],"predecessor-version":[{"id":209892,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/155577\/revisions\/209892"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/162936"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=155577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=155577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=155577"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=155577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}