{"id":77,"date":"2023-04-19T18:27:59","date_gmt":"2023-04-19T18:27:59","guid":{"rendered":"https:\/\/www.roadomain.com\/web\/blog\/?p=77"},"modified":"2023-04-23T09:21:29","modified_gmt":"2023-04-23T09:21:29","slug":"9-tricks-you-can-use-in-the-htaccess-file-for-wordpress","status":"publish","type":"post","link":"https:\/\/www.roadomain.com\/web\/blog\/9-tricks-you-can-use-in-the-htaccess-file-for-wordpress\/","title":{"rendered":"9 tricks you can use in the htaccess file for WordPress"},"content":{"rendered":"<p><strong>make site faster<\/strong><br \/>\nEnable gzip compression: Gzip compresses your website files before sending them to the user&#8217;s browser, which reduces the file size and makes your site load faster. Add the following code to your .htaccess file:<\/p>\n<p>&lt;IfModule mod_deflate.c&gt;<br \/>\n# Compress HTML, CSS, JavaScript, Text, XML and fonts<br \/>\nAddOutputFilterByType DEFLATE application\/javascript<br \/>\nAddOutputFilterByType DEFLATE application\/rss+xml<br \/>\nAddOutputFilterByType DEFLATE application\/vnd.ms-fontobject<br \/>\nAddOutputFilterByType DEFLATE application\/x-font<br \/>\nAddOutputFilterByType DEFLATE application\/x-font-opentype<br \/>\nAddOutputFilterByType DEFLATE application\/x-font-otf<br \/>\nAddOutputFilterByType DEFLATE application\/x-font-truetype<br \/>\nAddOutputFilterByType DEFLATE application\/x-font-ttf<br \/>\nAddOutputFilterByType DEFLATE application\/x-javascript<br \/>\nAddOutputFilterByType DEFLATE application\/xhtml+xml<br \/>\nAddOutputFilterByType DEFLATE application\/xml<br \/>\nAddOutputFilterByType DEFLATE font\/opentype<br \/>\nAddOutputFilterByType DEFLATE font\/otf<br \/>\nAddOutputFilterByType DEFLATE font\/ttf<br \/>\nAddOutputFilterByType DEFLATE image\/svg+xml<br \/>\nAddOutputFilterByType DEFLATE image\/x-icon<br \/>\nAddOutputFilterByType DEFLATE text\/css<br \/>\nAddOutputFilterByType DEFLATE text\/html<br \/>\nAddOutputFilterByType DEFLATE text\/javascript<br \/>\nAddOutputFilterByType DEFLATE text\/plain<br \/>\nAddOutputFilterByType DEFLATE text\/xml<\/p>\n<p># Remove browser bugs (only needed for really old browsers)<br \/>\nBrowserMatch ^Mozilla\/4 gzip-only-text\/html<br \/>\nBrowserMatch ^Mozilla\/4\\.0[678] no-gzip<br \/>\nBrowserMatch \\bMSIE !no-gzip !gzip-only-text\/html<br \/>\nHeader append Vary User-Agent<br \/>\n&lt;\/IfModule&gt;<\/p>\n<p>Leverage browser caching: This instructs the user&#8217;s browser to store certain files (such as images, CSS, and JavaScript) in its cache, so they don&#8217;t have to be downloaded again on subsequent visits. Add the following code to your .htaccess file:<\/p>\n<p>&lt;IfModule mod_expires.c&gt;<br \/>\nExpiresActive On<br \/>\nExpiresByType image\/jpg &#8220;access 1 year&#8221;<br \/>\nExpiresByType image\/jpeg &#8220;access 1 year&#8221;<br \/>\nExpiresByType image\/gif &#8220;access 1 year&#8221;<br \/>\nExpiresByType image\/png &#8220;access 1 year&#8221;<br \/>\nExpiresByType text\/css &#8220;access 1 month&#8221;<br \/>\nExpiresByType text\/html &#8220;access 1 month&#8221;<br \/>\nExpiresByType application\/pdf &#8220;access 1 month&#8221;<br \/>\nExpiresByType text\/x-javascript &#8220;access 1 month&#8221;<br \/>\nExpiresByType application\/x-shockwave-flash &#8220;access 1 month&#8221;<br \/>\nExpiresByType image\/x-icon &#8220;access 1 year&#8221;<br \/>\nExpiresDefault &#8220;access 1 month&#8221;<br \/>\n&lt;\/IfModule&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>Enable caching headers: This sets HTTP headers that instruct the user&#8217;s browser to cache certain files for a specific amount of time. Add the following code to your .htaccess file:<\/p>\n<p>&lt;IfModule mod_headers.c&gt;<br \/>\n&lt;FilesMatch &#8220;\\.(ico|jpe?g|png|gif|swf|css|js)$&#8221;&gt;<br \/>\nHeader set Cache-Control &#8220;max-age=2592000, public&#8221;<br \/>\n&lt;\/FilesMatch&gt;<br \/>\n&lt;\/IfModule&gt;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>make site more secure<\/strong><br \/>\nBlock directory browsing: This prevents anyone from being able to browse the contents of your website&#8217;s directories. Add the following code to your .htaccess file:<\/p>\n<p>Options -Indexes<\/p>\n<p>Prevent hotlinking: This prevents other websites from using your images and other media files by linking to them directly. Add the following code to your .htaccess file:<\/p>\n<p>RewriteEngine On<br \/>\nRewriteCond %{HTTP_REFERER} !^$<br \/>\nRewriteCond %{HTTP_REFERER} !^http(s)?:\/\/(www\\.)?yourwebsite.com [NC]<br \/>\nRewriteRule \\.(jpg|jpeg|png|gif)$ &#8211; [NC,F,L]<\/p>\n<p>Make sure to replace &#8220;yourwebsite.com&#8221; with your actual website URL.<br \/>\nSet proper file permissions: This prevents unauthorized users from accessing your website files. The following code sets the correct file permissions for your WordPress installation:<\/p>\n<p>&lt;Files wp-config.php&gt;<br \/>\nOrder allow,deny<br \/>\nDeny from all<br \/>\n&lt;\/Files&gt;<\/p>\n<p># Block the include-only files.<br \/>\n&lt;IfModule mod_rewrite.c&gt;<br \/>\nRewriteEngine On<br \/>\nRewriteBase \/<br \/>\nRewriteRule ^wp-admin\/includes\/ &#8211; [F,L]<br \/>\nRewriteRule !^wp-includes\/ &#8211; [S=3]<br \/>\nRewriteRule ^wp-includes\/[^\/]+\\.php$ &#8211; [F,L]<br \/>\nRewriteRule ^wp-includes\/js\/tinymce\/langs\/.+\\.php &#8211; [F,L]<br \/>\nRewriteRule ^wp-includes\/theme-compat\/ &#8211; [F,L]<br \/>\n&lt;\/IfModule&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>Limit login attempts: This prevents hackers from brute-forcing their way into your WordPress dashboard by limiting the number of login attempts. Add the following code to your .htaccess file:<\/p>\n<p>&lt;IfModule mod_authz_core.c&gt;<br \/>\n&lt;FilesMatch &#8220;wp-login.php&#8221;&gt;<br \/>\nAuthName &#8220;WordPress Login&#8221;<br \/>\nAuthType Basic<br \/>\nAuthUserFile \/dev\/null<br \/>\nRequire valid-user<br \/>\nLimitRequestBody 102400<br \/>\n&lt;\/FilesMatch&gt;<br \/>\n&lt;\/IfModule&gt;<br \/>\n&lt;Files wp-login.php&gt;<br \/>\nLimitRequestBody 102400<br \/>\n&lt;\/Files&gt;<\/p>\n<p># Limit Login Attempts<br \/>\n&lt;IfModule mod_security.c&gt;<br \/>\nSecFilterEngine Off<br \/>\nSecFilterScanPOST Off<br \/>\n&lt;\/IfModule&gt;<br \/>\n&lt;IfModule mod_limitipconn.c&gt;<br \/>\n&lt;Location &#8220;\/wp-login.php&#8221;&gt;<br \/>\n# Increase timeout for client IP<br \/>\nLimitIPConnRemTime 3600<br \/>\n# Lock out the client IP after x failed attempts<br \/>\nLimitIPConn max 10<br \/>\n&lt;\/Location&gt;<br \/>\n&lt;\/IfModule&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>make site faster Enable gzip compression: Gzip compresses your website files before sending them to the user&#8217;s browser, which reduces the file size and makes your site load faster. Add the following code to your .htaccess file: &lt;IfModule mod_deflate.c&gt; # Compress HTML, CSS, JavaScript, Text, XML and fonts AddOutputFilterByType DEFLATE application\/javascript AddOutputFilterByType DEFLATE application\/rss+xml AddOutputFilterByType [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":390,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-77","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.roadomain.com\/web\/blog\/wp-json\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.roadomain.com\/web\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.roadomain.com\/web\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.roadomain.com\/web\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.roadomain.com\/web\/blog\/wp-json\/wp\/v2\/comments?post=77"}],"version-history":[{"count":2,"href":"https:\/\/www.roadomain.com\/web\/blog\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":80,"href":"https:\/\/www.roadomain.com\/web\/blog\/wp-json\/wp\/v2\/posts\/77\/revisions\/80"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.roadomain.com\/web\/blog\/wp-json\/wp\/v2\/media\/390"}],"wp:attachment":[{"href":"https:\/\/www.roadomain.com\/web\/blog\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.roadomain.com\/web\/blog\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.roadomain.com\/web\/blog\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}