{"id":29903,"date":"2017-05-02T23:01:48","date_gmt":"2017-05-02T15:01:48","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=29903"},"modified":"2022-10-18T20:12:24","modified_gmt":"2022-10-18T12:12:24","slug":"useful-htaccess-snippets-for-wordpress","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/","title":{"rendered":"15 Useful .htaccess Snippets for Your WordPress Site"},"content":{"rendered":"<p>Having a <strong>well-configured .htaccess file<\/strong> is crucial if you want to <strong>increase security<\/strong> and <strong>reduce vulnerabilities<\/strong> on your WordPress site. Usually, the main goal of creating a <strong>custom .htaccess file<\/strong> is to prevent your site from being hacked but it\u2019s also an excellent way to handle redirects and manage cache-related tasks.<\/p>\n<p>.htaccess is a <strong>configuration file<\/strong> used on Apache web servers. Most WordPress sites <strong><a href=\"https:\/\/wordpress.org\/about\/requirements\/\" target=\"_blank\" rel=\"noopener\">run on an Apache server<\/a><\/strong>, although a small portion is <strong><a href=\"https:\/\/codex.wordpress.org\/Nginx\" target=\"_blank\" rel=\"noopener\">powered by Nginx<\/a><\/strong>. In this article, you can find a <strong>collection of  .htaccess code snippets<\/strong>, most of which you can use to secure your website while the rest implements other useful features.<\/p>\n<p class=\"recommended_top\">\n\t\t\t\t\t<strong>Read Also:<\/strong>\u00a0\n\t\t\t\t\t<a target=\"_blank\" href=\"https:\/\/www.hongkiat.com\/blog\/guide-to-htaccess\/\">A Beginner\u2019s Guide to .htaccess for Designers and Developers<\/a>\n\t\t\t\t<\/p>\n<p>Don\u2019t forget to <strong>back up the .htaccess file<\/strong> before you edit it so that you can always <strong>return to the previous version<\/strong> if something goes wrong.<\/p>\n<p>And, if you\u2019re someone who rather not touch configuration files I recommend you the <strong><a href=\"https:\/\/wordpress.org\/plugins\/bulletproof-security\/\" target=\"_blank\" rel=\"noopener\">BulletProof Security<\/a><\/strong> plugin which is the most reliable (and probably the oldest) <strong>free .htaccess security plugin<\/strong> on the market.<\/p>\n<h2>Create the default WP .htaccess<\/h2>\n<p>.htaccess works on a <strong>per-directory basis<\/strong> which means that each directory can have its own .htaccess file. It can easily happen that your WordPress site <strong><a href=\"https:\/\/www.wpbeginner.com\/beginners-guide\/why-you-cant-find-htaccess-file-on-your-wordpress-site\/\" target=\"_blank\" rel=\"noopener\">doesn\u2019t have a .htaccess file yet<\/a><\/strong>. If you don\u2019t find a .htaccess file in your root directory <strong>create an empty text file<\/strong> and name it to <code>.htaccess<\/code>.<\/p>\n<p>Below, you can find the <strong>default .htaccess<\/strong> WordPress uses. Whenever you need this code you can quickly look it up in the <a href=\"https:\/\/codex.wordpress.org\/htaccess\" target=\"_blank\" rel=\"noopener\">WordPress Codex<\/a>. Note that there is a different .htaccess for <a href=\"https:\/\/codex.wordpress.org\/htaccess#Multisite\" target=\"_blank\" rel=\"noopener\">WP Multisite<\/a>.<\/p>\n<pre>\r\n# BEGIN WordPress\r\n&lt;IfModule mod_rewrite.c&gt;\r\nRewriteEngine On\r\nRewriteBase \/\r\nRewriteRule ^index\\.php$ - [L]\r\nRewriteCond %{REQUEST_FILENAME} !-f\r\nRewriteCond %{REQUEST_FILENAME} !-d\r\nRewriteRule . \/index.php [L]\r\n&lt;\/IfModule&gt;\r\n# END WordPress\r\n<\/pre>\n<p>The lines beginning with <code>#<\/code> are comments. <strong>Don\u2019t edit anything<\/strong> between the lines <code># BEGIN WordPress<\/code> and <code># END WordPress<\/code>. Add your custom .htaccess rules <strong>below these default rules<\/strong>.<\/p>\n<p>All code snippets you can find in this article <strong>go to the core .htaccess file<\/strong> found in your root directory.<\/p>\n<h2>1. Deny access to all .htaccess files<\/h2>\n<p>The code below <strong>denies access<\/strong> to all .htaccess files you have installed in your WordPress. This way you can prevent people from seeing your <strong>web server configurations<\/strong>.<\/p>\n<pre>\r\n# Denies access to all .htaccess files\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>\n<h2>2. Protect your WP configuration<\/h2>\n<p>The <code>wp-config.php<\/code> file contains <strong>all your WP configurations<\/strong>, including your database login and password. You can either deny it from everyone or <strong>give permission to admins to access it<\/strong>.<\/p>\n<p>If you choose the latter <strong>comment out<\/strong> the <code># Allow from xx.xx.xx.xxx<\/code> line (remove <code>#<\/code> from the beginning of the line) and <strong>insert the admin\u2019s IP address<\/strong> in place of <code>xx.xx.xx.xxx<\/code>.<\/p>\n<pre>\r\n# Protects wp-config\r\n&lt;Files wp-config.php&gt;\r\nOrder Allow,Deny\r\n# Allow from xx.xx.xx.xxx\r\n# Allow from yy.yy.yy.yyy\r\nDeny from all\r\n&lt;\/Files&gt;\r\n<\/pre>\n<h2>3. Prevent XML-RPC DDoS attack<\/h2>\n<p>WordPress <strong><a href=\"https:\/\/codex.wordpress.org\/XML-RPC_Support\" target=\"_blank\" rel=\"noopener\">supports XML-RPC<\/a><\/strong> by default, which is an <strong>interface that makes remote publishing<\/strong> possible. However, while it\u2019s a great feature, it\u2019s also one of WP\u2019s biggest security vulnerability as hackers may <strong><a href=\"https:\/\/blog.sucuri.net\/2014\/03\/more-than-162000-wordpress-sites-used-for-distributed-denial-of-service-attack.html\" target=\"_blank\" rel=\"noopener\">exploit it for DDoS attacks<\/a><\/strong>.<\/p>\n<p>If you don\u2019t want to use this feature it\u2019s better to just <strong>disable it<\/strong>. Just like before, you can <strong>add exceptions by commenting out<\/strong> the <code># Allow from xx.xx.xx.xxx<\/code> line and adding the IPs of your admin(s).<\/p>\n<pre>\r\n# Protects XML-RPC, prevents DDoS attack\r\n&lt;FilesMatch \"^(xmlrpc\\.php)\"&gt;\r\nOrder Deny,Allow\r\n# Allow from xx.xx.xx.xxx\r\n# Allow from yy.yy.yy.yyy\r\nDeny from all\r\n&lt;\/FilesMatch&gt;\r\n<\/pre>\n<h2>4. Protect your admin area<\/h2>\n<p>It\u2019s also a good idea to <strong>protect the admin area<\/strong> by giving access only to administrators. Here, don\u2019t forget to <strong>add at least one \u201cAllow\u201d exception<\/strong> otherwise you won\u2019t be able to access your admin at all.<\/p>\n<pre>\r\n# Protects admin area by IP\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\nAllow from xx.xx.xx.xxx\r\nAllow from yy.yy.yy.yyy\r\n&lt;\/LIMIT&gt;\r\n<\/pre>\n<h2>5. Prevent directory listing<\/h2>\n<p>Most WordPress sites don\u2019t disable directory listing, which means anyone can <strong>browse their folders and files<\/strong>, including media uploads and plugin files. It\u2019s needless to say that this is a huge security vulnerability.<\/p>\n<p>Below, you can see how a <strong>typical WordPress directory listing looks like<\/strong>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/useful-htaccess-snippets-for-wordpress\/directory-listing.jpg\" width=\"655\" height=\"294\" alt=\"Directory listing\"><\/figure>\n<p>Luckily, you just need <strong>one line of code<\/strong> to block this feature. This code snippet will <strong>return a 403 error message<\/strong> to anyone who wants to access your directories.<\/p>\n<pre>\r\n# Prevents directory listing\r\nOptions -Indexes\r\n<\/pre>\n<h2>6. Prevent username enumeration<\/h2>\n<p>If WP permalinks are enabled, it\u2019s quite easy to <strong>enumerate usernames<\/strong> using the author archives. The revealed usernames (including the admin\u2019s username) then can be used in <strong><a href=\"https:\/\/www.techopedia.com\/definition\/18091\/brute-force-attack\" target=\"_blank\" rel=\"noopener nofollow\">brute force attacks<\/a><\/strong>.<\/p>\n<p>Insert the code below into your .htaccess file to <strong>prevent username enumeration<\/strong>.<\/p>\n<pre>\r\n# Prevents username  enumeration\r\nRewriteCond %{QUERY_STRING} author=d\r\nRewriteRule ^ \/? [L,R=301]\r\n<\/pre>\n<h2>7. Block spammers and bots<\/h2>\n<p>Sometimes you may want to <strong>restrict access from certain IP addresses<\/strong>. This code snippet provides an easy way to block spammers and bots you already know.<\/p>\n<pre>\r\n# Blocks spammers and bots\r\n&lt;Limit GET POST&gt;\r\nOrder Allow,Deny\r\nDeny from xx.xx.xx.xxx\r\nDeny from yy.yy.yy.yyy\r\n&lt;\/Limit&gt;\r\nAllow from all\r\n<\/pre>\n<h2>8. Prevent image hotlinking<\/h2>\n<p>Although not a security threat, <strong><a href=\"https:\/\/www.hongkiat.com\/blog\/smarter-way-to-prevent-image-hotlinking-with-htaccess\/\">image hotlinking<\/a><\/strong> is still an annoying thing. People don\u2019t only <strong>use your images without your permission<\/strong> but they even do it at your cost. With these few lines of code, you can protect your site from image hotlinking.<\/p>\n<pre>\r\n# Prevents image hotlinking\r\nRewriteEngine on\r\nRewriteCond %{HTTP_REFERER} !^$\r\nRewriteCond %{HTTP_REFERER} !^http(s)?:\/\/(www\\.)?yourwebsite.com [NC]\r\nRewriteCond %{HTTP_REFERER} !^http(s)?:\/\/(www\\.)?yourwebsite2.com [NC]\r\nRewriteRule \\.(jpe?g?|png|gif|ico|pdf|flv|swf|gz)$ - [NC,F,L]\r\n<\/pre>\n<h2>9. Restrict direct access to plugin & theme PHP files<\/h2>\n<p>It can be dangerous if someone <strong>directly calls your plugin and theme files<\/strong>, whether it happens accidentally or by a malicious attacker. This code snippet <strong>comes from the Acunetix website security company<\/strong>; you can read more about this vulnerability in their <a href=\"https:\/\/www.acunetix.com\/websitesecurity\/wordpress-security-top-tips-secure-wordpress-application\/\" target=\"_blank\" rel=\"noopener\">blog post<\/a>.<\/p>\n<pre>\r\n# Restricts access to PHP files from plugin and theme directories\r\nRewriteCond %{REQUEST_URI} !^\/wp-content\/plugins\/file\/to\/exclude\\.php\r\nRewriteCond %{REQUEST_URI} !^\/wp-content\/plugins\/directory\/to\/exclude\/\r\nRewriteRule wp-content\/plugins\/(.*\\.php)$ - [R=404,L]\r\nRewriteCond %{REQUEST_URI} !^\/wp-content\/themes\/file\/to\/exclude\\.php\r\nRewriteCond %{REQUEST_URI} !^\/wp-content\/themes\/directory\/to\/exclude\/\r\nRewriteRule wp-content\/themes\/(.*\\.php)$ - [R=404,L]\r\n<\/pre>\n<h2>10. Set up permanent redirects<\/h2>\n<p>You can easily <strong>handle permanent redirects<\/strong> with .htaccess. First you have to add the <strong>old URL<\/strong>, then follow the <strong>new URL<\/strong> that points to the page you want to redirect the user to.<\/p>\n<pre>\r\n# Permanent redirects\r\nRedirect 301 \/oldurl1\/ http:\/\/yoursite.com\/newurl1\r\nRedirect 301 \/oldurl2\/ http:\/\/yoursite.com\/newurl2\r\n<\/pre>\n<h2>11. Send visitors to a maintenance page<\/h2>\n<p>We wrote about this technique in detail <a href=\"https:\/\/www.hongkiat.com\/blog\/wordpress-maintenance\/\">here<\/a>. You need a <strong>separate maintenance page<\/strong> (<code>maintenance.html<\/code> in the example) for this .htaccess rule to work. This code puts your WordPress site <strong>into maintenance mode<\/strong>.<\/p>\n<pre>\r\n# Redirects to maintenance page\r\n&lt;IfModule mod_rewrite.c&gt;\r\nRewriteEngine on\r\nRewriteCond %{REMOTE_ADDR} !^123\\.456\\.789\\.000\r\nRewriteCond %{REQUEST_URI} !\/maintenance.html$ [NC]\r\nRewriteCond %{REQUEST_URI} !\\.(jpe?g?|png|gif) [NC]\r\nRewriteRule .* \/maintenance.html [R=503,L]\r\n&lt;\/IfModule&gt;\r\n<\/pre>\n<h2>12. Restrict all access to WP includes<\/h2>\n<p>The <code>\/wp-includes\/<\/code> folder <strong>contains the core WordPress files<\/strong> that are necessary for the CMS to work. There are no content, plugins, themes or anything else a user may want to access here. So to harden security it\u2019s best to <strong>restrict all access to it<\/strong>.<\/p>\n<pre>\r\n# Blocks all wp-includes folders and files\r\n&lt;IfModule mod_rewrite.c&gt;\r\nRewriteEngine On\r\nRewriteBase \/\r\nRewriteRule ^wp-admin\/includes\/ - [F,L]\r\nRewriteRule !^wp-includes\/ - [S=3]\r\nRewriteRule ^wp-includes\/[^\/]+\\.php$ - [F,L]\r\nRewriteRule ^wp-includes\/js\/tinymce\/langs\/.+\\.php - [F,L]\r\nRewriteRule ^wp-includes\/theme-compat\/ - [F,L]\r\n&lt;\/IfModule&gt;\r\n<\/pre>\n<h2>13. Block cross-site scripting (XSS)<\/h2>\n<p>The following code snippet is from <a href=\"https:\/\/wp-mix.com\/block-xss-htaccess\/\" target=\"_blank\" rel=\"noopener\">WP Mix<\/a> and it protects your site against <strong>some common XSS attacks<\/strong>, namely script injections and attempts to modify global and request variables.<\/p>\n<pre>\r\n# Blocks some XSS attacks\r\n&lt;IfModule mod_rewrite.c&gt;\r\nRewriteCond %{QUERY_STRING} (\\<|%3C).*script.*(\\>|%3E) [NC,OR]\r\nRewriteCond %{QUERY_STRING} GLOBALS(=|\\[|\\%[0-9A-Z]{0,2}) [OR]\r\nRewriteCond %{QUERY_STRING} _REQUEST(=|\\[|\\%[0-9A-Z]{0,2})\r\nRewriteRule .* index.php [F,L]\r\n&lt;\/IfModule&gt;\r\n<\/pre>\n<h2>14. Enable browser caching<\/h2>\n<p>As I mentioned before, .htaccess is not only good for security reasons and redirections but it can also help you <strong>manage the cache<\/strong>. The code snippet below is from <a href=\"https:\/\/www.elegantthemes.com\/blog\/tips-tricks\/wordpress-htaccess-tips-and-tricks\" target=\"_blank\" rel=\"noopener\">Elegant Themes<\/a> and it <strong>makes browser caching possible<\/strong> by enabling visitors to <strong>save certain kinds of files<\/strong>, so next time they visit they don\u2019t have to download them again.<\/p>\n<pre>\r\n# Enables browser caching\r\n&lt;IfModule mod_expires.c&gt;\r\nExpiresActive On\r\nExpiresByType image\/jpg \"access 1 year\"\r\nExpiresByType image\/jpeg \"access 1 year\"\r\nExpiresByType image\/gif \"access 1 year\"\r\nExpiresByType image\/png \"access 1 year\"\r\nExpiresByType text\/css \"access 1 month\"\r\nExpiresByType application\/pdf \"access 1 month\"\r\nExpiresByType text\/x-javascript \"access 1 month\"\r\nExpiresByType application\/x-shockwave-flash \"access 1 month\"\r\nExpiresByType image\/x-icon \"access 1 year\"\r\nExpiresDefault \"access 2 days\"\r\n&lt;\/IfModule&gt;\r\n<\/pre>\n<h2>15. Set up custom error pages<\/h2>\n<p>You can use .htaccess to set up custom error pages on your WordPress site. For this method to work, you also need to <strong>create the custom error pages<\/strong> (<code>custom-403.html<\/code>, <code>custom-404.html<\/code> in the example) and <strong>upload them<\/strong> to your root folder.<\/p>\n<p>You can set up a custom error page for <strong>any <a href=\"https:\/\/www.hongkiat.com\/blog\/common-http-errors\/\">HTTP error status code<\/a><\/strong> (4XX and 5XX status codes) you want.<\/p>\n<pre>\r\n# Sets up custom error pages\r\nErrorDocument 403 \/custom-403.html\r\nErrorDocument 404 \/custom-404.html\r\n<\/pre>\n<p class=\"recommended_top\">\n\t\t\t\t\t<strong>Read Also:<\/strong>\u00a0\n\t\t\t\t\t<a target=\"_blank\" href=\"https:\/\/www.hongkiat.com\/blog\/wordpress-maintenance\/\">How to Enable Maintenance Mode on Your WordPress Site<\/a>\n\t\t\t\t<\/p>","protected":false},"excerpt":{"rendered":"<p>Having a well-configured .htaccess file is crucial if you want to increase security and reduce vulnerabilities on your WordPress site. Usually, the main goal of creating a custom .htaccess file is to prevent your site from being hacked but it\u2019s also an excellent way to handle redirects and manage cache-related tasks. .htaccess is a configuration&hellip;<\/p>\n","protected":false},"author":146,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[49],"tags":[4663,952,3325,252],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>15 Useful .htaccess Snippets for Your WordPress Site - Hongkiat<\/title>\n<meta name=\"description\" content=\"Having a well-configured .htaccess file is crucial if you want to increase security and reduce vulnerabilities on your WordPress site. Usually, the main\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"15 Useful .htaccess Snippets for Your WordPress Site\" \/>\n<meta property=\"og:description\" content=\"Having a well-configured .htaccess file is crucial if you want to increase security and reduce vulnerabilities on your WordPress site. Usually, the main\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2017-05-02T15:01:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-18T12:12:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/useful-htaccess-snippets-for-wordpress\/directory-listing.jpg\" \/>\n<meta name=\"author\" content=\"Anna Monus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anna Monus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/\"},\"author\":{\"name\":\"Anna Monus\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/a601053a0ab457901e00cdc83bd5359e\"},\"headline\":\"15 Useful .htaccess Snippets for Your WordPress Site\",\"datePublished\":\"2017-05-02T15:01:48+00:00\",\"dateModified\":\"2022-10-18T12:12:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/\"},\"wordCount\":1046,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/useful-htaccess-snippets-for-wordpress\\\/directory-listing.jpg\",\"keywords\":[\"ad-divi\",\"htaccess\",\"WordPress Security\",\"WordPress Tips\"],\"articleSection\":[\"WordPress\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/\",\"name\":\"15 Useful .htaccess Snippets for Your WordPress Site - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/useful-htaccess-snippets-for-wordpress\\\/directory-listing.jpg\",\"datePublished\":\"2017-05-02T15:01:48+00:00\",\"dateModified\":\"2022-10-18T12:12:24+00:00\",\"description\":\"Having a well-configured .htaccess file is crucial if you want to increase security and reduce vulnerabilities on your WordPress site. Usually, the main\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/useful-htaccess-snippets-for-wordpress\\\/directory-listing.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/useful-htaccess-snippets-for-wordpress\\\/directory-listing.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/useful-htaccess-snippets-for-wordpress\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"15 Useful .htaccess Snippets for Your WordPress Site\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/a601053a0ab457901e00cdc83bd5359e\",\"name\":\"Anna Monus\",\"description\":\"Anna is Technical Editor and Writer for Hongkiat.com. She mainly covers front-end frameworks, web standards, accessibility, WordPress development, and UX design.\",\"sameAs\":[\"https:\\\/\\\/www.annalytic.com\\\/\"],\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/anna_monus\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"15 Useful .htaccess Snippets for Your WordPress Site - Hongkiat","description":"Having a well-configured .htaccess file is crucial if you want to increase security and reduce vulnerabilities on your WordPress site. Usually, the main","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/","og_locale":"en_US","og_type":"article","og_title":"15 Useful .htaccess Snippets for Your WordPress Site","og_description":"Having a well-configured .htaccess file is crucial if you want to increase security and reduce vulnerabilities on your WordPress site. Usually, the main","og_url":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2017-05-02T15:01:48+00:00","article_modified_time":"2022-10-18T12:12:24+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/useful-htaccess-snippets-for-wordpress\/directory-listing.jpg","type":"","width":"","height":""}],"author":"Anna Monus","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Anna Monus","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/"},"author":{"name":"Anna Monus","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/a601053a0ab457901e00cdc83bd5359e"},"headline":"15 Useful .htaccess Snippets for Your WordPress Site","datePublished":"2017-05-02T15:01:48+00:00","dateModified":"2022-10-18T12:12:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/"},"wordCount":1046,"commentCount":5,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/useful-htaccess-snippets-for-wordpress\/directory-listing.jpg","keywords":["ad-divi","htaccess","WordPress Security","WordPress Tips"],"articleSection":["WordPress"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/","url":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/","name":"15 Useful .htaccess Snippets for Your WordPress Site - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/useful-htaccess-snippets-for-wordpress\/directory-listing.jpg","datePublished":"2017-05-02T15:01:48+00:00","dateModified":"2022-10-18T12:12:24+00:00","description":"Having a well-configured .htaccess file is crucial if you want to increase security and reduce vulnerabilities on your WordPress site. Usually, the main","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/useful-htaccess-snippets-for-wordpress\/directory-listing.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/useful-htaccess-snippets-for-wordpress\/directory-listing.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/useful-htaccess-snippets-for-wordpress\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"15 Useful .htaccess Snippets for Your WordPress Site"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/a601053a0ab457901e00cdc83bd5359e","name":"Anna Monus","description":"Anna is Technical Editor and Writer for Hongkiat.com. She mainly covers front-end frameworks, web standards, accessibility, WordPress development, and UX design.","sameAs":["https:\/\/www.annalytic.com\/"],"url":"https:\/\/www.hongkiat.com\/blog\/author\/anna_monus\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-7Mj","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/29903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/146"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=29903"}],"version-history":[{"count":3,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/29903\/revisions"}],"predecessor-version":[{"id":61685,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/29903\/revisions\/61685"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=29903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=29903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=29903"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=29903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}