{"id":84875,"date":"2018-06-13T11:25:12","date_gmt":"2018-06-13T15:25:12","guid":{"rendered":"https:\/\/www.templatemonster.com\/help\/?p=84875"},"modified":"2020-02-06T10:47:55","modified_gmt":"2020-02-06T15:47:55","slug":"12-most-useful-htaccess-tricks-for-wordpress","status":"publish","type":"post","link":"https:\/\/www.templatemonster.com\/help\/12-most-useful-htaccess-tricks-for-wordpress.html","title":{"rendered":"12 most useful .htaccess tricks for WordPress"},"content":{"rendered":"<p>Hello, our support team is ready to present you a new tutorial about <strong>12 most useful .htaccess tricks<\/strong> for WordPress.<\/p>\r\n<p>The <strong>.htaccess<\/strong> file is a server configuration file which allows you to define rules for your server to follow for your website. <\/p>\r\n<p>WordPress usually uses .htaccess file to generate SEO friendly URLs. However, this file can be used for other various goals.<\/p>\r\n<p>The .htaccess file is located in your WordPress site\u2019s root folder. You will need to connect to your website using an FTP client to edit it.<\/p>\r\n<ol>\r\n<li><p>Protect Your WordPress Admin Area<\/p>\r\n<p>Simply copy and paste this code into your .htaccess file:<\/p>\r\n<pre>\r\nAuthUserFile \/dev\/null\r\nAuthGroupFile \/dev\/null\r\nAuthName \"WordPress Admin Access Control\"\r\nAuthType Basic\r\n&lt;LIMIT GET&gt;\r\norder deny,allow\r\ndeny from all\r\n# whitelist Syed's IP address\r\nallow from xx.xx.xx.xxx\r\n# whitelist David's IP address\r\nallow from xx.xx.xx.xxx\r\n&lt;\/LIMIT&gt;\r\n<\/pre>\r\n<p>You need to replace xx values with your own IP address<\/p> \r\n\r\n<\/li>\r\n<li><p>Password Protect WordPress Admin Folder<\/p>\r\n<p>You can use .htaccess file to add an additional password protection to your WordPress admin area.<\/p>\r\n<ol>\r\n<li><p>First, you need to generate a .htpasswds file. You can do it by using this <a href=\"http:\/\/www.htaccesstools.com\/htpasswd-generator\/\">online generator.<\/a><\/p><\/li>\r\n<li><p>Upload this .htpasswds file outside your publicly accessible web directory or \/public_html\/ folder. For example: \/public_html\/wp-admin\/passwd\/<\/p><\/li>\r\n<li><p>Create a .htaccess file and upload it in \/wp-admin\/ directory and then add the following codes in there:<\/p> \r\n<pre>AuthName \"Admins Only\"\r\nAuthUserFile \/home\/yourdirectory\/.htpasswds\/public_html\/wp-admin\/passwd\r\nAuthGroupFile \/dev\/null\r\nAuthType basic\r\nrequire user putyourusernamehere\r\n&lt;Files admin-ajax.php&gt;\r\nOrder allow,deny\r\nAllow from all\r\nSatisfy any \r\n&lt;\/Files&gt;\r\n<\/pre>\r\n<\/li>\r\n<li><p>Replace AuthUserFile path with the file path of your .htpasswds file and add your own username<\/p>\r\n<\/li>\r\n<\/ol>\r\n<\/li>\r\n\r\n<li><p>Disable Directory Browsing<\/p>\r\n\r\n<p>To disable directory browsing on your website, you need to add the following line to your .htaccess file:<\/p>\r\n<pre>\r\nOptions -Indexes\r\n<\/pre>\r\n\r\n<\/li>\r\n<li><p>Disable PHP Execution in Some WordPress Directories<\/p>\r\n<p>You can increase WordPress security by disabling PHP execution for some WordPress directories.\r\nYou will need to create an empty .htaccess file on your computer and then paste the following code inside it:<\/p>\r\n<pre>\r\n&lt;Files *.php&gt;\r\ndeny from all\r\n&lt;\/Files&gt;\r\n<\/pre>\r\n<\/li>\r\n<li><p>Protect Your WordPress Configuration wp-config.php File<\/p>\r\n<p>To protect your wp-config.php file from unathorized access, just add the following  code to your .htaccess file:<\/p>\r\n<pre>\r\n&lt;files wp-config.php&gt;\r\norder allow,deny\r\ndeny from all\r\n&lt;\/files&gt;\r\n<\/pre>\r\n\r\n<\/li>\r\n<li><p>Setting up 301 Redirects Through .htaccess File<\/p>\r\n<p>Using 301 redirects is the most SEO friendly way to tell your users that a content has moved to a new location. You can set up redirects by adding the following code to .htaccess file:<\/p>\r\n<pre>\r\nRedirect 301 \/oldurl\/ http:\/\/www.example.com\/newurl\r\nRedirect 301 \/category\/television\/ \r\nhttp:\/\/www.example.com\/category\/tv\/\r\n<\/pre>\r\n<\/li>\r\n<li><p>Ban Suspicious IP Addresses<\/p>\r\n<p>Add the following code to your .htaccess file. Don\u2019t forget to replace xx with the IP address you want to block.<\/p>\r\n<pre>\r\n&lt;Limit GET POST&gt;\r\norder allow,deny\r\ndeny from xxx.xxx.xx.x\r\nallow from all\r\n&lt;\/Limit&gt;\r\n<\/pre>\r\n<\/li>\r\n<li><p>Disable Image Hotlinking in WordPress Using .htaccess<\/p>\r\n<p>You can prevent image hotlinking by adding this code to your .htaccess file:<\/p>\r\n<pre>\r\n#disable hotlinking of images with forbidden or custom image option\r\nRewriteEngine on\r\nRewriteCond %{HTTP_REFERER} !^$\r\nRewriteCond %{HTTP_REFERER} !^http(s)?:\/\/(www\\.)?wpbeginner.com [NC]\r\nRewriteCond %{HTTP_REFERER} !^http(s)?:\/\/(www\\.)?google.com [NC]\r\nRewriteRule \\.(jpg|jpeg|png|gif)$ \u2013 [NC,F,L] \r\n<\/pre>\r\n<\/li>\r\n<li><p>Protect .htaccess From Unauthorized Access<\/p>\r\n<p>Due to the power and control it has on your web server, it is important to protect it from unauthorized access by hackers. Simply add following code to your .htaccess file:<\/p>\r\n<pre>\r\n&lt;files ~ \"^.*\\.([Hh][Tt][Aa])\"&gt;\r\norder allow,deny\r\ndeny from all\r\nsatisfy all\r\n&lt;\/files&gt;\r\n<\/pre>\r\n<\/li>\r\n<li><p>Increase File Upload Size in WordPress<\/p>\r\n<p>You can do it by adding the following code to .htaccess file:<\/p>\r\n<pre>\r\nphp_value upload_max_filesize 64M\r\nphp_value post_max_size 64M\r\nphp_value max_execution_time 300\r\nphp_value max_input_time 300\r\n<\/pre>\r\n\r\n<\/li>\r\n<li><p>Disable Access to XML-RPC File Using .htaccess<\/p>\r\n<p>There are multiple ways to do that, one of them is by adding the following code to your .htaccess file:<\/p>\r\n<pre>\r\n# Block WordPress xmlrpc.php requests\r\n&lt;Files xmlrpc.php&gt;\r\norder deny,allow\r\ndeny from all\r\n&lt;\/Files&gt;\r\n<\/pre>\r\n<\/li>\r\n<li><p>Blocking Author Scans in WordPress<\/p>\r\n<p>A common technique used in brute force attacks is to run author scans on a WordPress site and then attempt to crack passwords for those usernames.\r\n\r\nYou can block such scans by adding the following code to your .htaccess file:<\/p>\r\n<pre>\r\n# BEGIN block author scans\r\nRewriteEngine On\r\nRewriteBase \/\r\nRewriteCond %{QUERY_STRING} (author=\\d+) [NC]\r\nRewriteRule .* - [F]\r\n# END block author scans \r\n<\/pre>\r\n<\/li>\r\n<\/ol>\r\n<p>Browse the selection of <a href=\"https:\/\/www.templatemonster.com\/wordpress-themes.php\" title=\"WordPress Themes\" target=\"_blank\">WordPress Themes<\/a> to view latest designs and learn more about WordPress features.<\/p>","protected":false},"excerpt":{"rendered":"<p>Hello, our support team is ready to present you a new tutorial about <strong>12 most useful .htaccess tricks<\/strong> for WordPress.<\/p>\n","protected":false},"author":56,"featured_media":84891,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2017,728],"tags":[1929,609],"_links":{"self":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/84875"}],"collection":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/users\/56"}],"replies":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/comments?post=84875"}],"version-history":[{"count":6,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/84875\/revisions"}],"predecessor-version":[{"id":86445,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/84875\/revisions\/86445"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media\/84891"}],"wp:attachment":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media?parent=84875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/categories?post=84875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/tags?post=84875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}