{"id":2589,"date":"2020-10-01T13:49:07","date_gmt":"2020-10-01T13:49:07","guid":{"rendered":"https:\/\/www.copahost.com\/blog\/?p=2589"},"modified":"2026-10-13T12:46:27","modified_gmt":"2026-10-13T12:46:27","slug":"htaccess","status":"publish","type":"post","link":"https:\/\/www.copahost.com\/blog\/htaccess\/","title":{"rendered":"WordPress .htaccess Generator, Default Code and Snippets"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>The <code>.htaccess<\/code> file is one of the most powerful configuration files on any WordPress site. This small text file sits in your site&#8217;s root folder and tells the Apache web server how to behave \u2014 handling your permalinks, forcing HTTPS, blocking attackers, speeding up your site, and setting up redirects. This guide covers everything: what the WordPress .htaccess file is, where to find it, how to create and edit it safely, the default WordPress code, and a library of ready-to-use snippets for security, performance, and redirects.<\/strong><\/p>\n\n\n\n<div style=\"display:flex; gap:14px; align-items:flex-start; background:#fff4ec; border:1px solid #f6c9a8; border-left:4px solid #F26C21; border-radius:8px; padding:16px 20px; margin:24px 0; font-family:Arial, Helvetica, sans-serif;\">\n  <div style=\"font-size:22px; flex-shrink:0; margin-top:1px;\">&#x26a0;&#xfe0f;<\/div>\n  <div style=\"flex:1;\">\n    <div style=\"font-weight:700; text-transform:uppercase; letter-spacing:0.08em; color:#c0441a; margin-bottom:6px;\">Back up before editing<\/div>\n    <p style=\"color:#1A2238; line-height:1.65; margin:0;\">The <code style=\"background:#fde8dc;border:1px solid #f6c9a8;border-radius:4px;padding:1px 5px;font-family:monospace;color:#8c2e10;\">.htaccess<\/code> file is read on every request. A single syntax error can take your whole site down with a 500 error. Always keep a copy of the working file before making changes \u2014 if something breaks, just re-upload it. Add one rule at a time and test after each.<\/p>\n  <\/div>\n<\/div>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_86 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.copahost.com\/blog\/htaccess\/#Build_your_WordPress_htaccess\" >Build your WordPress .htaccess<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.copahost.com\/blog\/htaccess\/#What_is_the_htaccess_file\" >What is the .htaccess file?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.copahost.com\/blog\/htaccess\/#Where_is_the_htaccess_file_in_WordPress\" >Where is the .htaccess file in WordPress?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.copahost.com\/blog\/htaccess\/#How_to_create_the_WordPress_htaccess_file\" >How to create the WordPress .htaccess file<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.copahost.com\/blog\/htaccess\/#The_default_WordPress_htaccess_code\" >The default WordPress .htaccess code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.copahost.com\/blog\/htaccess\/#Restoring_htaccess_and_the_500_error\" >Restoring .htaccess and the 500 error<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.copahost.com\/blog\/htaccess\/#Essential_htaccess_snippets_for_WordPress\" >Essential .htaccess snippets for WordPress<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.copahost.com\/blog\/htaccess\/#Other_common_uses\" >Other common uses<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.copahost.com\/blog\/htaccess\/#Frequently_asked_questions\" >Frequently asked questions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.copahost.com\/blog\/htaccess\/#Related_guides\" >Related guides<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.copahost.com\/blog\/htaccess\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Build_your_WordPress_htaccess\"><\/span>Build your WordPress .htaccess<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"cp-hta\" id=\"cp-hta\" style=\"max-width:780px;margin:28px auto;border:1px solid #c9d2dd;border-radius:14px;padding:22px 24px;background:#f4f6f9;font-family:Arial,Helvetica,sans-serif;color:#0F172A;font-size:15px;\">\n<div style=\"font-weight:800;font-size:19px;color:#1A2238;margin-bottom:4px;\">.htaccess builder for WordPress<\/div>\n<p style=\"margin:0 0 12px;line-height:1.5;font-size:14.5px;\">Pick the rules you want and copy a complete .htaccess, with the WordPress block in the right place. Paste your current file to keep its rules and check it for common problems.<\/p>\n<div style=\"display:flex;gap:12px;flex-wrap:wrap;\">\n<div style=\"flex:1 1 300px;min-width:0;background:#ffffff;border:1px solid #d5dce5;border-radius:10px;padding:12px 14px;box-sizing:border-box;\">\n<div style=\"font-weight:800;font-size:13px;letter-spacing:.05em;text-transform:uppercase;color:#475569;margin-bottom:8px;\">WordPress rules<\/div>\n<label for=\"cp-hta-type\" style=\"display:block;font-size:14px;margin-bottom:4px;\">Installation<\/label>\n<select id=\"cp-hta-type\" style=\"width:100%;box-sizing:border-box;padding:8px;border:1px solid #9aa7b8;border-radius:8px;font-size:14px;background:#ffffff;color:#0F172A;\">\n<option value=\"single\">Single site<\/option>\n<option value=\"sub\">Multisite with subfolders<\/option>\n<option value=\"dom\">Multisite with subdomains<\/option>\n<option value=\"none\">Leave out the WordPress block<\/option>\n<\/select>\n<label for=\"cp-hta-path\" style=\"display:block;font-size:14px;margin:10px 0 4px;\">Site path<\/label>\n<input type=\"text\" id=\"cp-hta-path\" value=\"\/\" autocomplete=\"off\" spellcheck=\"false\" style=\"width:100%;box-sizing:border-box;padding:8px 10px;border:1px solid #9aa7b8;border-radius:8px;font-family:Consolas,Menlo,monospace;font-size:14px;\">\n<div style=\"font-size:12.5px;color:#64748b;margin-top:4px;line-height:1.4;\">Keep \/ when the site opens at the domain root. Use \/blog\/ for example.com\/blog\/.<\/div>\n<\/div>\n<div style=\"flex:1 1 300px;min-width:0;background:#ffffff;border:1px solid #d5dce5;border-radius:10px;padding:12px 14px;box-sizing:border-box;\">\n<div style=\"font-weight:800;font-size:13px;letter-spacing:.05em;text-transform:uppercase;color:#475569;margin-bottom:8px;\">Security<\/div>\n<label style=\"display:flex;gap:8px;align-items:flex-start;font-size:14px;margin:5px 0;line-height:1.35;\"><input type=\"checkbox\" id=\"cp-hta-cfg\" checked style=\"width:auto;flex:0 0 auto;margin:2px 0 0;\">Protect wp-config.php<\/label>\n<label style=\"display:flex;gap:8px;align-items:flex-start;font-size:14px;margin:5px 0;line-height:1.35;\"><input type=\"checkbox\" id=\"cp-hta-logs\" checked style=\"width:auto;flex:0 0 auto;margin:2px 0 0;\">Block logs, backups and SQL dumps<\/label>\n<label style=\"display:flex;gap:8px;align-items:flex-start;font-size:14px;margin:5px 0;line-height:1.35;\"><input type=\"checkbox\" id=\"cp-hta-hid\" checked style=\"width:auto;flex:0 0 auto;margin:2px 0 0;\">Block hidden files like .git and .env<\/label>\n<label style=\"display:flex;gap:8px;align-items:flex-start;font-size:14px;margin:5px 0;line-height:1.35;\"><input type=\"checkbox\" id=\"cp-hta-idx\" checked style=\"width:auto;flex:0 0 auto;margin:2px 0 0;\">Turn off directory listing<\/label>\n<label style=\"display:flex;gap:8px;align-items:flex-start;font-size:14px;margin:5px 0;line-height:1.35;\"><input type=\"checkbox\" id=\"cp-hta-up\" checked style=\"width:auto;flex:0 0 auto;margin:2px 0 0;\">Block PHP in the uploads folder<\/label>\n<label style=\"display:flex;gap:8px;align-items:flex-start;font-size:14px;margin:5px 0;line-height:1.35;\"><input type=\"checkbox\" id=\"cp-hta-inc\" style=\"width:auto;flex:0 0 auto;margin:2px 0 0;\">Block direct access to wp-includes<\/label>\n<label style=\"display:flex;gap:8px;align-items:flex-start;font-size:14px;margin:5px 0;line-height:1.35;\"><input type=\"checkbox\" id=\"cp-hta-xml\" style=\"width:auto;flex:0 0 auto;margin:2px 0 0;\">Block xmlrpc.php<\/label>\n<\/div>\n<div style=\"flex:1 1 300px;min-width:0;background:#ffffff;border:1px solid #d5dce5;border-radius:10px;padding:12px 14px;box-sizing:border-box;\">\n<div style=\"font-weight:800;font-size:13px;letter-spacing:.05em;text-transform:uppercase;color:#475569;margin-bottom:8px;\">Speed<\/div>\n<label style=\"display:flex;gap:8px;align-items:flex-start;font-size:14px;margin:5px 0;line-height:1.35;\"><input type=\"checkbox\" id=\"cp-hta-gz\" checked style=\"width:auto;flex:0 0 auto;margin:2px 0 0;\">Compress text files (Gzip)<\/label>\n<label style=\"display:flex;gap:8px;align-items:flex-start;font-size:14px;margin:5px 0;line-height:1.35;\"><input type=\"checkbox\" id=\"cp-hta-exp\" checked style=\"width:auto;flex:0 0 auto;margin:2px 0 0;\">Browser caching for images, CSS, JS and fonts<\/label>\n<label for=\"cp-hta-per\" style=\"display:block;font-size:14px;margin:8px 0 4px;\">Keep static files for<\/label>\n<select id=\"cp-hta-per\" style=\"width:100%;box-sizing:border-box;padding:8px;border:1px solid #9aa7b8;border-radius:8px;font-size:14px;background:#ffffff;color:#0F172A;\">\n<option value=\"1 week\">1 week<\/option>\n<option value=\"1 month\" selected>1 month<\/option>\n<option value=\"6 months\">6 months<\/option>\n<option value=\"1 year\">1 year<\/option>\n<\/select>\n<\/div>\n<div style=\"flex:1 1 300px;min-width:0;background:#ffffff;border:1px solid #d5dce5;border-radius:10px;padding:12px 14px;box-sizing:border-box;\">\n<div style=\"font-weight:800;font-size:13px;letter-spacing:.05em;text-transform:uppercase;color:#475569;margin-bottom:8px;\">Headers<\/div>\n<label style=\"display:flex;gap:8px;align-items:flex-start;font-size:14px;margin:5px 0;line-height:1.35;\"><input type=\"checkbox\" id=\"cp-hta-hdr\" checked style=\"width:auto;flex:0 0 auto;margin:2px 0 0;\">Security headers (nosniff, frame and referrer policies)<\/label>\n<label style=\"display:flex;gap:8px;align-items:flex-start;font-size:14px;margin:5px 0;line-height:1.35;\"><input type=\"checkbox\" id=\"cp-hta-hsts\" style=\"width:auto;flex:0 0 auto;margin:2px 0 0;\">HSTS: browsers always use HTTPS<\/label>\n<\/div>\n<\/div>\n<label for=\"cp-hta-cur\" style=\"display:block;font-weight:700;font-size:14px;color:#1A2238;margin:14px 0 4px;\">Your current .htaccess (optional)<\/label>\n<textarea id=\"cp-hta-cur\" rows=\"5\" placeholder=\"Paste it here to keep its rules, skip what it already has and check it for problems\" spellcheck=\"false\" autocomplete=\"off\" style=\"display:block;width:100%;box-sizing:border-box;padding:10px 12px;border:1px solid #9aa7b8;border-radius:8px;font-family:Consolas,Menlo,monospace;font-size:13px;line-height:1.45;resize:vertical;background:#ffffff;color:#0F172A;\"><\/textarea>\n<div id=\"cp-hta-st\" aria-live=\"polite\" style=\"margin-top:12px;font-size:14px;color:#334155;\"><\/div>\n<div id=\"cp-hta-out\" aria-live=\"polite\" style=\"margin-top:8px;\"><\/div>\n<p style=\"margin:14px 0 0;font-size:12.5px;color:#475569;line-height:1.5;\">For Apache and LiteSpeed; Nginx ignores .htaccess files. Rules tested on Apache 2.4. Nothing you paste leaves your browser. Source: copahost.com<\/p>\n<\/div>\n<script>(function () { var NL = String.fromCharCode(10); var CR = String.fromCharCode(13); var LT = String.fromCharCode(60); var GT = String.fromCharCode(62); var BS = String.fromCharCode(92); var Q = String.fromCharCode(34); var DOT = String.fromCharCode(183); var BLOG = \"https:\/\/www.copahost.com\/blog\/\"; var COL = {ok: [\"#15803d\", \"#e8f5ec\", String.fromCharCode(10004)], warn: [\"#b45309\", \"#fff4e5\", String.fromCharCode(9888)], err: [\"#b42318\", \"#fdecec\", String.fromCharCode(10006)], info: [\"#1d4ed8\", \"#eef3ff\", String.fromCharCode(8505)]}; var RANK = {err: 0, warn: 1, ok: 2, info: 3}; var LINK = \"color:#1d4ed8;font-weight:700;\"; var MONO = \"font-family:Consolas,Menlo,monospace;\"; var IDS = [\"type\", \"path\", \"cfg\", \"logs\", \"hid\", \"idx\", \"up\", \"inc\", \"xml\", \"gz\", \"exp\", \"per\", \"hdr\", \"hsts\"]; function el(id) { return document.getElementById(id); } function f(id) { return el(\"cp-hta-\" + id); } function add(p, tag, text, style) { var n = document.createElement(tag); if (text) { n.textContent = text; } if (style) { n.setAttribute(\"style\", style); } p.appendChild(n); return n; } function has(s, x) { return String(s).indexOf(x) !== -1; } function gt(a, b) { return a === b ? false : Math.max(a, b) === a; } function say(arr, l, t, href, lt2) { arr.push({l: l, t: t, h: href || \"\", lt: lt2 || \"\"}); } function T(lines) { return lines.join(NL).split(\"[[\").join(LT).split(\"]]\").join(GT).split(\"@\").join(BS).split(\"'\").join(Q); } function deny(open, close) { return [open, \"[[IfModule mod_authz_core.c]]\", \"Require all denied\", \"[[\/IfModule]]\", \"[[IfModule !mod_authz_core.c]]\", \"Order allow,deny\", \"Deny from all\", \"[[\/IfModule]]\", close]; } function cleanPath(p) { var s = String(p || \"\").trim(); var cut = s.indexOf(\":\" + \"\/\" + \"\/\"); if (cut !== -1) { s = s.slice(cut + 3); var sl = s.indexOf(\"\/\"); s = sl === -1 ? \"\/\" : s.slice(sl); } s = s.split(\"?\")[0].split(\"#\")[0].split(\" \").join(\"\"); var out = \"\"; for (var i = 0; i !== s.length; i++) { var c = s.charAt(i); if (has(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.\/~\", c)) { out += c; } } if (out.charAt(0) !== \"\/\") { out = \"\/\" + out; } if (out.charAt(out.length - 1) !== \"\/\") { out = out + \"\/\"; } var dbl = \"\/\" + \"\/\"; while (has(out, dbl)) { out = out.split(dbl).join(\"\/\"); } return out; } function wpBlock(type, path) { if (type === \"single\") { return T([\"# BEGIN WordPress\", \"# The directives (lines) between 'BEGIN WordPress' and 'END WordPress' are\", \"# dynamically generated, and should only be modified via WordPress filters.\", \"# Any changes to the directives between these markers will be overwritten.\", \"[[IfModule mod_rewrite.c]]\", \"RewriteEngine On\", \"RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]\", \"RewriteBase \" + path, \"RewriteRule ^index@.php$ - [L]\", \"RewriteCond %{REQUEST_FILENAME} !-f\", \"RewriteCond %{REQUEST_FILENAME} !-d\", \"RewriteRule . \" + path + \"index.php [L]\", \"[[\/IfModule]]\", \"\", \"# END WordPress\"]); } var sub = type === \"sub\"; var m = sub ? \"([_0-9a-zA-Z-]+\/)?\" : \"\"; return T([\"# BEGIN WordPress Multisite\", \"# Using \" + (sub ? \"subfolder\" : \"subdomain\") + \" network type: https:\/\/wordpress.org\/documentation\/article\/htaccess\/#multisite\", \"\", \"RewriteEngine On\", \"RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]\", \"RewriteBase \/\", \"RewriteRule ^index@.php$ - [L]\", \"\", \"# add a trailing slash to \/wp-admin\", \"RewriteRule ^\" + m + \"wp-admin$ \" + (sub ? \"$1\" : \"\") + \"wp-admin\/ [R=301,L]\", \"\", \"RewriteCond %{REQUEST_FILENAME} -f [OR]\", \"RewriteCond %{REQUEST_FILENAME} -d\", \"RewriteRule ^ - [L]\", \"RewriteRule ^\" + m + \"(wp-(content|admin|includes).*) \" + (sub ? \"$2\" : \"$1\") + \" [L]\", \"RewriteRule ^\" + m + \"(.*@.php)$ \" + (sub ? \"$2\" : \"$1\") + \" [L]\", \"RewriteRule . index.php [L]\", \"\", \"# END WordPress Multisite\"]); } function detect(e) { var s = e.toLowerCase(); var wpCount = s.split(\"# begin wordpress\").length - 1; return { cfg: has(s, \"wp-config.php\"), logs: has(s, \"debug.log\") ? true : (has(s, \"error_log\") ? true : has(s, \"|log|\")), hid: has(s, \"well-known\") ? true : has(s, \"(^|\/)\" + BS + \".\"), idx: has(s, \"-indexes\"), up: has(s, \"wp-content\/uploads\") ? has(s, \"php\") : false, inc: has(s, \"theme-compat\") ? true : has(s, \"wp-includes\/[^\/]\"), xml: has(s, \"xmlrpc\"), gz: has(s, \"deflate\") ? true : has(s, \"brotli\"), exp: has(s, \"expiresbytype\") ? true : has(s, \"expiresdefault\"), hdr: has(s, \"x-content-type-options\"), hsts: has(s, \"strict-transport-security\"), wp: gt(wpCount, 0) ? true : has(s, \"index.php [l]\"), wpCount: wpCount, multi: has(s, \"wp-admin$\") }; } function plugins(e) { var names = [[\"# begin lscache\", \"LiteSpeed Cache\"], [\"# begin w3tc\", \"W3 Total Cache\"], [\"# begin wp rocket\", \"WP Rocket\"], [\"# begin wpfastestcache\", \"WP Fastest Cache\"], [\"# begin wp-optimize\", \"WP-Optimize\"], [\"# begin wp super cache\", \"WP Super Cache\"], [\"# begin wpsupercache\", \"WP Super Cache\"], [\"# begin really simple ssl\", \"Really Simple SSL\"], [\"# begin rlrssslreallysimplessl\", \"Really Simple SSL\"], [\"# begin itheme\", \"iThemes Security\"], [\"# begin solid security\", \"Solid Security\"], [\"# begin wordfence\", \"Wordfence\"], [\"# begin all in one wp security\", \"All In One WP Security\"], [\"# begin aiowps\", \"All In One WP Security\"], [\"# begin cpanel-generated php ini directives\", \"cPanel PHP settings\"], [\"# php -- begin cpanel-generated handler\", \"cPanel PHP handler\"]]; var s = e.toLowerCase(); var out = []; for (var i = 0; i !== names.length; i++) { if (has(s, names[i][0]) ? out.indexOf(names[i][1]) === -1 : false) { out.push(names[i][1]); } } return out; } function insideWp(e) { var lines = e.split(NL); var inside = false; var odd = []; var ok = [\"rewriteengine on\", \"rewritebase\", \"rewriterule ^index\" + BS + \".php$ - [l]\", \"rewritecond %{request_filename} !-f\", \"rewritecond %{request_filename} !-d\", \"rewriterule .* - [e=http_authorization:%{http:authorization}]\"]; for (var i = 0; i !== lines.length; i++) { var s = lines[i].trim(); var lo = s.toLowerCase(); if (lo === \"# begin wordpress\") { inside = true; continue; } if (lo === \"# end wordpress\") { inside = false; continue; } if (!inside ? true : !s) { continue; } if (s.charAt(0) === \"#\") { continue; } if (lo.indexOf(LT + \"ifmodule\") === 0 ? true : lo.indexOf(LT + \"\/ifmodule\") === 0) { continue; } var good = false; for (var k = 0; k !== ok.length; k++) { if (lo.indexOf(ok[k]) === 0) { good = true; } } if (lo.indexOf(\"rewriterule . \") === 0 ? has(lo, \"index.php [l]\") : false) { good = true; } if (!good) { odd.push(s); } } return odd; } function build() { var o = {}; for (var i = 0; i !== IDS.length; i++) { var n = f(IDS[i]); o[IDS[i]] = n.type === \"checkbox\" ? n.checked : n.value; } var cur = String(f(\"cur\").value || \"\").split(CR).join(\"\"); var hasCur = cur.trim() !== \"\"; var d = hasCur ? detect(cur) : null; var type = o.type; var multi = type === \"sub\" ? true : type === \"dom\"; var path = multi ? \"\/\" : cleanPath(o.path); f(\"path\").disabled = type !== \"single\"; f(\"path\").style.opacity = type === \"single\" ? \"1\" : \"0.5\"; f(\"inc\").disabled = multi; f(\"per\").disabled = !o.exp; f(\"per\").style.opacity = o.exp ? \"1\" : \"0.5\"; var want = function (k) { return o[k] ? (d ? !d[k] : true) : false; }; var skipped = []; var LABEL = {cfg: \"wp-config.php protection\", logs: \"log and backup blocking\", hid: \"hidden file blocking\", idx: \"directory listing off\", up: \"uploads PHP blocking\", inc: \"wp-includes blocking\", xml: \"xmlrpc.php blocking\", gz: \"compression\", exp: \"browser caching\", hdr: \"security headers\", hsts: \"HSTS\"}; var keys = [\"cfg\", \"logs\", \"hid\", \"idx\", \"up\", \"inc\", \"xml\", \"gz\", \"exp\", \"hdr\", \"hsts\"]; for (var s0 = 0; s0 !== keys.length; s0++) { var k0 = keys[s0]; if (o[k0] ? (d ? d[k0] : false) : false) { if (k0 === \"inc\" ? !multi : true) { skipped.push(LABEL[k0]); } } } var parts = []; var notes = []; if (want(\"cfg\")) { parts.push(T([\"# Protect wp-config.php\"].concat(deny(\"[[Files wp-config.php]]\", \"[[\/Files]]\")))); } if (want(\"logs\")) { parts.push(T([\"# Block logs, backups and SQL dumps\"].concat(deny(\"[[FilesMatch '(^error_log|@.(bak|log|old|orig|sql|swp)|~)$']]\", \"[[\/FilesMatch]]\")))); } if (want(\"idx\")) { parts.push(T([\"# Turn off directory listing\", \"Options -Indexes\"])); } var rw = []; if (want(\"hid\")) { rw = rw.concat([\"# Block hidden files and folders such as .git and .env, except .well-known\", \"RewriteCond %{REQUEST_URI} '!(^|\/)@.well-known\/([^.\/]+.\/?)+$' [NC]\", \"RewriteCond %{SCRIPT_FILENAME} -d [OR]\", \"RewriteCond %{SCRIPT_FILENAME} -f\", \"RewriteRule '(^|\/)@.' - [F]\"]); } if (want(\"up\")) { rw = rw.concat([\"# Block PHP files in the uploads folder\", \"RewriteRule ^wp-content\/uploads\/.*@.(?:php[0-9]?|pht|phtml|phar)$ - [NC,F]\"]); } if (want(\"inc\") ? !multi : false) { rw = rw.concat([\"# Block the include-only files\", \"RewriteRule ^wp-admin\/includes\/ - [F,L]\", \"RewriteRule !^wp-includes\/ - [S=3]\", \"RewriteRule ^wp-includes\/[^\/]+@.php$ - [F,L]\", \"RewriteRule ^wp-includes\/js\/tinymce\/langs\/.+@.php - [F,L]\", \"RewriteRule ^wp-includes\/theme-compat\/ - [F,L]\"]); } if (rw.length) { parts.push(T([\"[[IfModule mod_rewrite.c]]\", \"RewriteEngine On\"].concat(rw, [\"[[\/IfModule]]\"]))); } if (want(\"xml\")) { parts.push(T([\"# Block xmlrpc.php\"].concat(deny(\"[[Files xmlrpc.php]]\", \"[[\/Files]]\")))); } var hd = []; if (want(\"hdr\")) { hd = hd.concat([\"Header always set X-Content-Type-Options 'nosniff'\", \"Header always set X-Frame-Options 'SAMEORIGIN'\", \"Header always set Referrer-Policy 'strict-origin-when-cross-origin'\"]); } if (want(\"hsts\")) { hd.push(\"Header always set Strict-Transport-Security 'max-age=31536000'\"); } if (hd.length) { parts.push(T([\"# Security headers\", \"[[IfModule mod_headers.c]]\"].concat(hd, [\"[[\/IfModule]]\"]))); } if (want(\"gz\")) { parts.push(T([\"# Compress text files\", \"[[IfModule mod_deflate.c]]\", \"[[IfModule mod_filter.c]]\", \"AddOutputFilterByType DEFLATE text\/html text\/plain text\/css text\/xml text\/javascript application\/javascript application\/json application\/ld+json application\/xml application\/rss+xml application\/atom+xml application\/manifest+json image\/svg+xml image\/x-icon image\/vnd.microsoft.icon font\/ttf font\/otf application\/vnd.ms-fontobject\", \"[[\/IfModule]]\", \"[[\/IfModule]]\"])); } if (want(\"exp\")) { var per = \"'access plus \" + o.per + \"'\"; var types = [\"image\/jpeg\", \"image\/png\", \"image\/gif\", \"image\/webp\", \"image\/avif\", \"image\/svg+xml\", \"image\/x-icon\", \"image\/vnd.microsoft.icon\", \"text\/css\", \"text\/javascript\", \"application\/javascript\", \"font\/woff2\", \"font\/woff\", \"font\/ttf\", \"font\/otf\", \"application\/vnd.ms-fontobject\", \"video\/mp4\", \"video\/webm\", \"audio\/mpeg\", \"application\/pdf\"]; var ex = [\"# Browser caching for static files\", \"[[IfModule mod_expires.c]]\", \"ExpiresActive On\"]; for (var t = 0; t !== types.length; t++) { ex.push(\"ExpiresByType \" + types[t] + \" \" + per); } ex.push(\"ExpiresByType text\/html 'access plus 0 seconds'\"); ex.push(\"[[\/IfModule]]\"); parts.push(T(ex)); } var wpAdd = \"\"; if (type !== \"none\") { if (!d) { wpAdd = wpBlock(type, path); } else if (!d.wp) { wpAdd = wpBlock(type, path); } } var head = \"# Generated with the WordPress .htaccess builder at copahost.com\"; var text = \"\"; if (hasCur) { text = (parts.length ? T([head]) + NL + NL + parts.join(NL + NL) + NL + NL : \"\") + cur.trim() + (wpAdd ? NL + NL + wpAdd : \"\") + NL; } else { text = T([head]) + NL + NL + parts.join(NL + NL) + (parts.length ? NL + NL : \"\") + wpAdd + NL; } if (o.xml ? want(\"xml\") : false) { say(notes, \"info\", \"Jetpack, the WordPress mobile apps and some publishing tools connect through xmlrpc.php. Leave this off if you use any of them.\"); } if (o.idx ? want(\"idx\") : false) { say(notes, \"info\", \"If the site shows a 500 error after you save, your host doesn't allow Options in .htaccess: delete the Options -Indexes line.\"); } if (o.hsts ? want(\"hsts\") : false) { say(notes, \"warn\", \"Turn on HSTS only when the whole site already works over HTTPS. Browsers that receive it refuse plain HTTP for your domain for a year.\"); } if (o.exp ? want(\"exp\") : false) { say(notes, \"info\", \"WordPress adds ?ver= to its CSS and JavaScript, so updates still reach visitors. An image replaced under the same file name can take up to \" + o.per + \" to refresh for returning visitors.\"); } if (o.inc ? multi : false) { say(notes, \"info\", \"Blocking wp-includes is left out: on Multisite it stops ms-files.php from serving uploaded files.\"); } if (multi ? type !== \"none\" : false) { say(notes, \"info\", \"These are the network rules WordPress gives for a network installed at the domain root. If WordPress lives in a subfolder, copy the rules from Network Setup instead.\"); } if (type === \"single\" ? path !== \"\/\" : false) { say(notes, \"info\", \"WordPress block set for \" + path + \". Put this file in the folder where WordPress is installed.\"); } if (hasCur) { if (skipped.length) { say(notes, \"ok\", \"Already in your file, so not added again: \" + skipped.join(\", \") + \".\"); } var pl = plugins(cur); if (pl.length) { say(notes, \"info\", \"Blocks from \" + pl.join(\", \") + \" were kept as they are. Plugins rewrite their own blocks, so leave them unchanged.\"); } if (gt(d.wpCount, 1)) { say(notes, \"warn\", \"Your file has \" + d.wpCount + \" WordPress blocks. Keep one: delete the extra # BEGIN WordPress to # END WordPress sections.\"); } if (!d.wp ? type === \"none\" : false) { say(notes, \"warn\", \"No WordPress rewrite rules in your file. Without them, every page except the home page returns 404 when permalinks are on.\"); } if (d.wp ? (type !== \"none\" ? (multi ? !d.multi : d.multi) : false) : false) { say(notes, \"warn\", \"Your file has the \" + (d.multi ? \"Multisite\" : \"single-site\") + \" WordPress block, but you chose \" + (multi ? \"Multisite\" : \"a single site\") + \". It was left as it is: replace it with the right block if the setting is correct.\"); } if (!d.wp ? type !== \"none\" : false) { say(notes, \"info\", \"Your file had no WordPress rewrite rules, so the WordPress block was added at the end.\"); } var odd = insideWp(cur); if (odd.length) { say(notes, \"warn\", \"Custom lines inside the WordPress block, such as \" + odd[0] + \", are lost when WordPress saves permalinks. Move them above # BEGIN WordPress.\"); } var lo = cur.toLowerCase(); if (has(lo, \"php_value\") ? true : (has(lo, \"php_flag\") ? true : has(lo, \"php_admin_value\"))) { say(notes, \"warn\", \"php_value and php_flag lines cause a 500 error when PHP runs as PHP-FPM. If the site works, PHP runs as an Apache module or under LiteSpeed; if it doesn't, move those settings to .user.ini.\", BLOG + \"php-default-settings\/#cp-php\", \"Check your PHP settings\"); } if (has(lo, \"deny from all\") ? true : (has(lo, \"order allow,deny\") ? true : has(lo, \"order deny,allow\"))) { say(notes, \"info\", \"Some of your rules use the old Apache 2.2 syntax (Order, Deny from). Apache 2.4 still reads it through a compatibility module, but Require all denied is the current form.\"); } if (has(lo, \"rewriteengine off\")) { say(notes, \"warn\", \"Your file contains RewriteEngine Off, which turns off WordPress permalinks and every rewrite rule below it.\"); } } if (hasCur ? false : (parts.length === 0 ? wpAdd === \"\" : false)) { el(\"cp-hta-out\").textContent = \"\"; el(\"cp-hta-st\").textContent = \"Pick at least one rule, or keep the WordPress block, to build the file.\"; return; } render(text, notes, hasCur, parts.length, wpAdd !== \"\"); } function badgeNote(parent, arr) { arr = arr.slice().sort(function (a, b) { return RANK[a.l] - RANK[b.l]; }); for (var i = 0; i !== arr.length; i++) { var n = arr[i]; var c = COL[n.l]; var d = add(parent, \"div\", \"\", \"background:\" + c[1] + \";border-left:4px solid \" + c[0] + \";border-radius:6px;padding:7px 10px;margin:6px 0;font-size:14px;line-height:1.5;color:#0F172A;word-break:break-word;\"); add(d, \"span\", c[2] + \" \", \"color:\" + c[0] + \";font-weight:800;\"); d.appendChild(document.createTextNode(n.t + \" \")); if (n.h) { add(d, \"a\", n.lt, LINK).setAttribute(\"href\", n.h); } } } function render(text, notes, hasCur, nParts, wpAdded) { var out = el(\"cp-hta-out\"); out.textContent = \"\"; var lines = text.trim().split(NL).length; el(\"cp-hta-st\").textContent = hasCur ? (nParts ? \"Your file with \" + nParts + \" new section\" + (nParts === 1 ? \"\" : \"s\") + \" added at the top\" + (wpAdded ? \" and the WordPress block at the end\" : \"\") + \": \" + lines + \" lines.\" : \"Nothing new to add\" + (wpAdded ? \" except the WordPress block\" : \"\") + \": \" + lines + \" lines.\") : \"Your .htaccess: \" + lines + \" lines.\"; var box = add(out, \"div\", \"\", \"background:#ffffff;border:1px solid #d5dce5;border-radius:10px;padding:12px 14px;\"); var top = add(box, \"div\", \"\", \"display:flex;justify-content:space-between;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:6px;\"); add(top, \"div\", \".htaccess\", \"font-weight:800;color:#1A2238;font-size:16px;\" + MONO); var btn = add(top, \"button\", \"Copy\", \"padding:6px 16px;border:0;background:#1A2238;color:#ffffff;border-radius:8px;cursor:pointer;font-weight:700;font-size:14px;\"); btn.setAttribute(\"type\", \"button\"); var pre = add(box, \"pre\", text, \"margin:0;background:#0F172A;color:#f1f5f9;border-radius:8px;padding:12px 14px;font-size:13px;line-height:1.55;white-space:pre-wrap;word-break:break-all;max-height:420px;overflow:auto;\" + MONO); btn.addEventListener(\"click\", function () { function done() { btn.textContent = \"Copied\"; setTimeout(function () { btn.textContent = \"Copy\"; }, 1500); } function manual() { var r = document.createRange(); r.selectNodeContents(pre); var sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(r); btn.textContent = \"Press Ctrl+C\"; } if (navigator.clipboard ? navigator.clipboard.writeText : false) { navigator.clipboard.writeText(text).then(done, manual); } else { manual(); } }); add(box, \"p\", \"Save a copy of your current .htaccess first. Then replace its whole content with this, in the folder where WordPress is installed (usually public_html), and load a few pages and the admin to check that everything opens.\", \"margin:10px 0 0;font-size:13.5px;line-height:1.5;color:#334155;\"); var links = add(box, \"div\", \"\", \"margin-top:6px;font-size:13.5px;line-height:1.7;\"); links.appendChild(document.createTextNode(\"Redirects for HTTPS, www or moved pages: \")); add(links, \"a\", \"redirect generator\", LINK).setAttribute(\"href\", BLOG + \"how-to-redirect-a-url-to-another-url\/\"); links.appendChild(document.createTextNode(\"  \" + DOT + \"  500 error after saving: \")); add(links, \"a\", \"how to fix it\", LINK).setAttribute(\"href\", BLOG + \"how-to-fix-500-internal-server-error\/\"); if (notes.length) { badgeNote(out, notes); } } var timer = null; function later() { clearTimeout(timer); timer = setTimeout(build, 250); } for (var i = 0; i !== IDS.length; i++) { f(IDS[i]).addEventListener(\"change\", build); } f(\"path\").addEventListener(\"input\", later); f(\"cur\").addEventListener(\"input\", later); build(); })();<\/script>\n\n\n\n<p class=\"wp-block-paragraph\"><a name=\"title_01\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_the_htaccess_file\"><\/span>What is the .htaccess file?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The name <code>.htaccess<\/code> comes from &#8220;HyperText Access.&#8221; It&#8217;s a distributed configuration file for the <strong>Apache web server<\/strong>, working at the directory level: a rule you place in the root folder applies to your whole site, and you can also place a separate <code>.htaccess<\/code> inside a subfolder to affect only that directory. WordPress uses it most notably to handle <strong>pretty permalinks<\/strong> \u2014 the clean, readable URLs like <code>yoursite.com\/about<\/code> instead of <code>yoursite.com\/?p=42<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the right directives you can force HTTPS, block IP addresses, deny access to sensitive files, set up redirects, prevent hotlinking, enable compression, and much more. It&#8217;s plain text, so you can edit it in any text editor.<\/p>\n\n\n\n<div style=\"display:flex; gap:14px; align-items:flex-start; background:#eef1f8; border:1px solid #b9c2dd; border-left:4px solid #1A2238; border-radius:8px; padding:16px 20px; margin:24px 0; font-family:Arial, Helvetica, sans-serif;\">\n  <div style=\"font-size:22px; flex-shrink:0; margin-top:1px;\">&#x1f4a1;<\/div>\n  <div style=\"flex:1;\">\n    <div style=\"font-weight:700; text-transform:uppercase; letter-spacing:0.08em; color:#1A2238; margin-bottom:6px;\">Apache only \u2014 not Nginx<\/div>\n    <p style=\"color:#1A2238; line-height:1.65; margin:0;\">The <code style=\"background:#fff;border:1px solid #b9c2dd;border-radius:4px;padding:1px 5px;font-family:monospace;color:#1A2238;\">.htaccess<\/code> file only works on Apache servers (and compatible ones like LiteSpeed). <strong>Nginx does not use .htaccess<\/strong> \u2014 the same rules have to be set in the server&#8217;s main configuration instead. If your host runs Nginx, the snippets below won&#8217;t apply.<\/p>\n  <\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Where_is_the_htaccess_file_in_WordPress\"><\/span>Where is the .htaccess file in WordPress?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Your WordPress <code>.htaccess<\/code> lives in the <strong>root directory<\/strong> of your installation \u2014 usually the <code>public_html<\/code> folder, alongside <code>wp-config.php<\/code> and <code>wp-admin<\/code>. Because the name starts with a dot, it&#8217;s a <strong>hidden file<\/strong>: if you don&#8217;t see it, enable &#8220;show hidden files&#8221; (dotfiles) in your File Manager or FTP client.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can reach it through your hosting <strong>File Manager<\/strong> (in cPanel) or an <a href=\"https:\/\/www.copahost.com\/blog\/ftp-file-transfer\/\">FTP client<\/a> like FileZilla. If WordPress is installed in a subfolder, the file is inside that folder.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_create_the_WordPress_htaccess_file\"><\/span>How to create the WordPress .htaccess file<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If there&#8217;s no <code>.htaccess<\/code> in your root, WordPress usually creates one automatically. The simplest way to trigger that: in your dashboard, go to <strong>Settings \u2192 Permalinks<\/strong> and click <strong>Save Changes<\/strong> (without changing anything). WordPress regenerates the default file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If it can&#8217;t (a file-permissions issue), create it manually: open a plain-text editor, save an empty file named exactly <code>.htaccess<\/code> (with the leading dot, no extension), set &#8220;Save as type&#8221; to <strong>All Files<\/strong> so it isn&#8217;t saved as <code>.txt<\/code>, and upload it to <code>public_html<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_default_WordPress_htaccess_code\"><\/span>The default WordPress .htaccess code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the standard block WordPress adds to make permalinks work. If your file is corrupted or your links suddenly 404, you can restore this:<\/p>\n\n\n\n<div style=\"margin:16px 0; font-family:Arial, Helvetica, sans-serif;\"><div style=\"background:#1A2238; border-radius:8px; padding:16px 20px; overflow-x:auto;\"><code style=\"display:block; color:#e6edf3; font-family:'Courier New',monospace; font-size:14px; line-height:1.7; white-space:pre;\"># BEGIN WordPress\n&lt;IfModule mod_rewrite.c&gt;\nRewriteEngine On\nRewriteBase \/\nRewriteRule ^index\\.php$ - [L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . \/index.php [L]\n&lt;\/IfModule&gt;\n# END WordPress<\/code><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Never edit anything between the <code># BEGIN WordPress<\/code> and <code># END WordPress<\/code> markers \u2014 WordPress rewrites that block automatically. Always add your custom rules <strong>outside<\/strong> (above or below) those markers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Restoring_htaccess_and_the_500_error\"><\/span>Restoring .htaccess and the 500 error<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>.htaccess<\/code> file is the number-one cause of the <a href=\"https:\/\/www.copahost.com\/blog\/how-to-fix-500-internal-server-error\/\">500 Internal Server Error<\/a> on WordPress. If your site goes down right after you edit it, the file is the prime suspect. The fastest test: rename the file (e.g. to <code>.htaccess_old<\/code>) via File Manager and reload the site. If it comes back, the problem was in the file \u2014 regenerate a clean one via <strong>Settings \u2192 Permalinks \u2192 Save Changes<\/strong>, or paste the default block above.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Essential_htaccess_snippets_for_WordPress\"><\/span>Essential .htaccess snippets for WordPress<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here are the most useful <code>.htaccess<\/code> rules for WordPress. Copy only the ones you need, always with a backup first, and place them outside the <code># BEGIN\/END WordPress<\/code> markers. To build the whole file at once, use the <a href=\"#cp-hta\">.htaccess builder<\/a> at the top of this page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Protect the wp-config.php file.<\/strong> Your most sensitive file \u2014 block all web access to it:<\/p>\n\n\n\n<div style=\"margin:16px 0; font-family:Arial, Helvetica, sans-serif;\"><div style=\"background:#1A2238; border-radius:8px; padding:16px 20px; overflow-x:auto;\"><code style=\"display:block; color:#e6edf3; font-family:'Courier New',monospace; font-size:14px; line-height:1.7; white-space:pre;\">&lt;Files wp-config.php&gt;\nRequire all denied\n&lt;\/Files&gt;<\/code><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Learn more in our full <a href=\"https:\/\/www.copahost.com\/blog\/wp-config-php\/\">wp-config.php guide<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Protect multiple sensitive files at once<\/strong> (wp-config, .htaccess, debug.log):<\/p>\n\n\n\n<div style=\"margin:16px 0; font-family:Arial, Helvetica, sans-serif;\"><div style=\"background:#1A2238; border-radius:8px; padding:16px 20px; overflow-x:auto;\"><code style=\"display:block; color:#e6edf3; font-family:'Courier New',monospace; font-size:14px; line-height:1.7; white-space:pre;\">&lt;FilesMatch \"^(wp-config\\.php|\\.htaccess|\\.htpasswd|debug\\.log)$\"&gt;\nRequire all denied\n&lt;\/FilesMatch&gt;<\/code><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Disable PHP execution in the uploads folder.<\/strong> Stops a malicious script uploaded to <code>wp-content\/uploads<\/code> from running (create this <code>.htaccess<\/code> inside that folder):<\/p>\n\n\n\n<div style=\"margin:16px 0; font-family:Arial, Helvetica, sans-serif;\"><div style=\"background:#1A2238; border-radius:8px; padding:16px 20px; overflow-x:auto;\"><code style=\"display:block; color:#e6edf3; font-family:'Courier New',monospace; font-size:14px; line-height:1.7; white-space:pre;\">&lt;FilesMatch \"(?i)\\.(php[0-9]?|pht|phtml|phar)$\"&gt;\nRequire all denied\n&lt;\/FilesMatch&gt;<\/code><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Block access by IP.<\/strong> Deny a specific abusive IP (replace <code>203.0.113.45<\/code> with the address you want to block):<\/p>\n\n\n\n<div style=\"margin:16px 0; font-family:Arial, Helvetica, sans-serif;\"><div style=\"background:#1A2238; border-radius:8px; padding:16px 20px; overflow-x:auto;\"><code style=\"display:block; color:#e6edf3; font-family:'Courier New',monospace; font-size:14px; line-height:1.7; white-space:pre;\">&lt;RequireAll&gt;\nRequire all granted\nRequire not ip 203.0.113.45\n&lt;\/RequireAll&gt;<\/code><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Force HTTPS (redirect HTTP to HTTPS).<\/strong> Once you have an SSL certificate installed, you&#8217;ll want every visitor on the secure <code>https:\/\/<\/code> version of your site \u2014 both for security and because Google uses HTTPS as a ranking signal. This rule redirects all HTTP traffic to HTTPS with a permanent (301) redirect:<\/p>\n\n\n\n<div style=\"margin:16px 0; font-family:Arial, Helvetica, sans-serif;\"><div style=\"background:#1A2238; border-radius:8px; padding:16px 20px; overflow-x:auto;\"><code style=\"display:block; color:#e6edf3; font-family:'Courier New',monospace; font-size:14px; line-height:1.7; white-space:pre;\">RewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} [L,R=301]<\/code><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Add it outside the <code># BEGIN\/END WordPress<\/code> markers. Two notes: if your site sits behind a proxy or CDN like Cloudflare, forcing HTTPS at both levels can cause a redirect loop \u2014 see our guide to <a href=\"https:\/\/www.copahost.com\/blog\/err-too-many-redirects\/\">ERR_TOO_MANY_REDIRECTS<\/a>. And WordPress can also enforce HTTPS through the Site Address setting; use one method, not both, to avoid conflicts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Force www or non-www (canonical domain).<\/strong> Your site shouldn&#8217;t answer on both <code>www.yoursite.com<\/code> and <code>yoursite.com<\/code> \u2014 search engines see them as two separate sites, splitting your SEO value. Pick one canonical version and redirect the other to it. To redirect <strong>www to non-www<\/strong>:<\/p>\n\n\n\n<div style=\"margin:16px 0; font-family:Arial, Helvetica, sans-serif;\"><div style=\"background:#1A2238; border-radius:8px; padding:16px 20px; overflow-x:auto;\"><code style=\"display:block; color:#e6edf3; font-family:'Courier New',monospace; font-size:14px; line-height:1.7; white-space:pre;\">RewriteEngine On\nRewriteCond %{HTTP_HOST} ^www\\.(.*)$ [NC]\nRewriteRule ^(.*)$ https:\/\/%1\/$1 [L,R=301]<\/code><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Or, to do the opposite and redirect <strong>non-www to www<\/strong>:<\/p>\n\n\n\n<div style=\"margin:16px 0; font-family:Arial, Helvetica, sans-serif;\"><div style=\"background:#1A2238; border-radius:8px; padding:16px 20px; overflow-x:auto;\"><code style=\"display:block; color:#e6edf3; font-family:'Courier New',monospace; font-size:14px; line-height:1.7; white-space:pre;\">RewriteEngine On\nRewriteCond %{HTTP_HOST} ^yoursite\\.com [NC]\nRewriteRule ^(.*)$ https:\/\/www.yoursite.com\/$1 [L,R=301]<\/code><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>yoursite.com<\/code> with your domain, and pick only <strong>one<\/strong> of the two \u2014 running both creates a loop. For more on permanent redirects, see our <a href=\"https:\/\/www.copahost.com\/blog\/http-301\/\">HTTP 301 guide<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Set up a 301 redirect.<\/strong> Point an old URL to a new one:<\/p>\n\n\n\n<div style=\"margin:16px 0; font-family:Arial, Helvetica, sans-serif;\"><div style=\"background:#1A2238; border-radius:8px; padding:16px 20px; overflow-x:auto;\"><code style=\"display:block; color:#e6edf3; font-family:'Courier New',monospace; font-size:14px; line-height:1.7; white-space:pre;\">Redirect 301 \/old-page https:\/\/yoursite.com\/new-page<\/code><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Enable Gzip compression.<\/strong> Shrinks files sent to the browser for faster loading:<\/p>\n\n\n\n<div style=\"margin:16px 0; font-family:Arial, Helvetica, sans-serif;\"><div style=\"background:#1A2238; border-radius:8px; padding:16px 20px; overflow-x:auto;\"><code style=\"display:block; color:#e6edf3; font-family:'Courier New',monospace; font-size:14px; line-height:1.7; white-space:pre;\">&lt;IfModule mod_deflate.c&gt;\nAddOutputFilterByType DEFLATE text\/html text\/plain text\/css\nAddOutputFilterByType DEFLATE application\/javascript text\/javascript\nAddOutputFilterByType DEFLATE application\/json application\/xml\n&lt;\/IfModule&gt;<\/code><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Leverage browser caching.<\/strong> Tell browsers to cache static assets:<\/p>\n\n\n\n<div style=\"margin:16px 0; font-family:Arial, Helvetica, sans-serif;\"><div style=\"background:#1A2238; border-radius:8px; padding:16px 20px; overflow-x:auto;\"><code style=\"display:block; color:#e6edf3; font-family:'Courier New',monospace; font-size:14px; line-height:1.7; white-space:pre;\">&lt;IfModule mod_expires.c&gt;\nExpiresActive On\nExpiresByType image\/jpeg \"access plus 1 year\"\nExpiresByType image\/png \"access plus 1 year\"\nExpiresByType image\/webp \"access plus 1 year\"\nExpiresByType text\/css \"access plus 1 month\"\nExpiresByType application\/javascript \"access plus 1 month\"\n&lt;\/IfModule&gt;<\/code><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prevent image hotlinking.<\/strong> Stop other sites from embedding your images and stealing bandwidth (replace <code>yoursite.com<\/code>):<\/p>\n\n\n\n<div style=\"margin:16px 0; font-family:Arial, Helvetica, sans-serif;\"><div style=\"background:#1A2238; border-radius:8px; padding:16px 20px; overflow-x:auto;\"><code style=\"display:block; color:#e6edf3; font-family:'Courier New',monospace; font-size:14px; line-height:1.7; white-space:pre;\">RewriteEngine On\nRewriteCond %{HTTP_REFERER} !^$\nRewriteCond %{HTTP_REFERER} !^https:\/\/(www\\.)?yoursite\\.com [NC]\nRewriteRule \\.(jpg|jpeg|png|gif|webp)$ - [F]<\/code><\/div><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Other_common_uses\"><\/span>Other common uses<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>.htaccess<\/code> file can do much more. A few common tasks have their own dedicated guides:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.copahost.com\/blog\/create-custom-404-error-page-htaccess\/\">Create a custom 404 error page<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.copahost.com\/blog\/password-protect-folder-site-htaccess\/\">Password-protect a folder<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.copahost.com\/blog\/how-to-redirect-a-url-to-another-url\/\">Redirect a URL to another URL<\/a><\/li>\n\n\n\n<li>Set up <a href=\"https:\/\/www.copahost.com\/blog\/http-301\/\">301 redirects<\/a> for moved content<\/li>\n<\/ul>\n\n\n\n<div style=\"max-width:760px; margin:32px auto; background:linear-gradient(135deg,#F26C21 0%,#1A2238 100%); border-radius:16px; padding:32px 28px; font-family:Arial, Helvetica, sans-serif; color:#fff; box-shadow:0 10px 30px rgba(242,108,33,.25);\">\n  <div style=\"display:flex; align-items:flex-start; gap:16px; flex-wrap:wrap;\">\n    <div style=\"flex:0 0 auto; display:inline-flex; align-items:center; justify-content:center; width:52px; height:52px; border-radius:12px; background:rgba(255,255,255,.18);\">\n      <svg width=\"28\" height=\"28\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#fff\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z\"><\/path><polyline points=\"14 2 14 8 20 8\"><\/polyline><line x1=\"16\" y1=\"13\" x2=\"8\" y2=\"13\"><\/line><line x1=\"16\" y1=\"17\" x2=\"8\" y2=\"17\"><\/line><\/svg>\n    <\/div>\n    <div style=\"flex:1 1 320px; min-width:260px;\">\n      <div style=\"font-weight:800; line-height:1.25; margin-bottom:8px;\">WordPress hosting built for speed and security<\/div>\n      <p style=\"margin:0 0 18px; line-height:1.6; color:#ffe4d3;\">The .htaccess file is one layer. Copahost runs on Apache\/LiteSpeed with cPanel access, free SSL, and support in your corner \u2014 so you can tune redirects, caching, and security without breaking your site.<\/p>\n      <a href=\"https:\/\/www.copahost.com\/web-hosting\/\" style=\"display:inline-flex; align-items:center; gap:8px; background:#fff; color:#F26C21; font-weight:700; text-decoration:none; padding:13px 26px; border-radius:10px; box-shadow:0 4px 12px rgba(0,0,0,.15);\">\n        See web hosting plans\n        <svg width=\"18\" height=\"18\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#F26C21\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M5 12h14M13 6l6 6-6 6\"><\/path><\/svg>\n      <\/a>\n    <\/div>\n  <\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Frequently_asked_questions\"><\/span>Frequently asked questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Where is the .htaccess file in WordPress?<\/strong><br>In the root directory of your install, usually the public_html folder, alongside wp-config.php. It&#8217;s a hidden file (the name starts with a dot), so you may need to enable &#8220;show hidden files&#8221; in your File Manager or FTP client to see it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>My WordPress site has no .htaccess file. How do I create one?<\/strong><br>Go to Settings \u2192 Permalinks and click Save Changes \u2014 WordPress regenerates the file automatically. If that fails due to permissions, create an empty file named exactly .htaccess in a text editor and upload it to public_html.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why did editing .htaccess cause a 500 error?<\/strong><br>A syntax error in .htaccess is the most common cause of a 500 Internal Server Error on WordPress. Rename the file to .htaccess_old to confirm, then regenerate a clean one via Settings \u2192 Permalinks \u2192 Save Changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Does .htaccess work on Nginx?<\/strong><br>No. The .htaccess file is specific to Apache (and compatible servers like LiteSpeed). Nginx doesn&#8217;t use it \u2014 equivalent rules must be added to the Nginx server configuration instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Where do I add custom rules in the WordPress .htaccess?<\/strong><br>Always outside the # BEGIN WordPress and # END WordPress markers \u2014 either above or below that block. WordPress automatically rewrites everything between those markers, so custom rules placed inside would be lost.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>How do I generate a WordPress .htaccess file?<\/strong><br>Use the <a href=\"#cp-hta\">.htaccess builder<\/a> at the top of this page. Pick the rules you want, such as <strong>wp-config.php protection<\/strong>, blocking PHP in uploads, compression, browser caching and security headers, and it writes a complete file with the WordPress block after your custom rules. <strong>Paste your current file into it<\/strong> to keep its rules and catch common problems, like a duplicated WordPress block.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [\n    {\"@type\":\"Question\",\"name\":\"Where is the .htaccess file in WordPress?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"In the root directory of your install, usually the public_html folder, alongside wp-config.php. It is a hidden file (the name starts with a dot), so you may need to enable show hidden files in your File Manager or FTP client to see it.\"}},\n    {\"@type\":\"Question\",\"name\":\"My WordPress site has no .htaccess file. How do I create one?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Go to Settings, Permalinks and click Save Changes. WordPress regenerates the file automatically. If that fails due to permissions, create an empty file named exactly .htaccess in a text editor and upload it to public_html.\"}},\n    {\"@type\":\"Question\",\"name\":\"Why did editing .htaccess cause a 500 error?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"A syntax error in .htaccess is the most common cause of a 500 Internal Server Error on WordPress. Rename the file to .htaccess_old to confirm, then regenerate a clean one via Settings, Permalinks, Save Changes.\"}},\n    {\"@type\":\"Question\",\"name\":\"Does .htaccess work on Nginx?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No. The .htaccess file is specific to Apache and compatible servers like LiteSpeed. Nginx does not use it, equivalent rules must be added to the Nginx server configuration instead.\"}},\n    {\"@type\":\"Question\",\"name\":\"Where do I add custom rules in the WordPress .htaccess?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Always outside the BEGIN WordPress and END WordPress markers, either above or below that block. WordPress automatically rewrites everything between those markers, so custom rules placed inside would be lost.\"}},\n    {\"@type\":\"Question\",\"name\":\"How do I generate a WordPress .htaccess file?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Use the .htaccess builder at the top of this page. Pick the rules you want, such as wp-config.php protection, blocking PHP in uploads, compression, browser caching and security headers, and it writes a complete file with the WordPress block after your custom rules. Paste your current file into it to keep its rules and catch common problems, like a duplicated WordPress block.\"}}\n  ]\n}<\/script>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Related_guides\"><\/span>Related guides<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The .htaccess file connects to several WordPress topics \u2014 see our guides on the <a href=\"https:\/\/www.copahost.com\/blog\/wp-config-php\/\">wp-config.php file<\/a>, <a href=\"https:\/\/www.copahost.com\/blog\/wordpress-login\/\">WordPress login and wp-admin<\/a>, the <a href=\"https:\/\/www.copahost.com\/blog\/how-to-fix-500-internal-server-error\/\">500 Internal Server Error<\/a>, and our hub of <a href=\"https:\/\/www.copahost.com\/blog\/common-wordpress-errors\/\">common WordPress errors<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The WordPress <code>.htaccess<\/code> file is small but mighty: it powers your permalinks, secures your most sensitive files, speeds up your site with compression and caching, and handles redirects that protect your SEO. You don&#8217;t need to be a developer to use it \u2014 just back up before editing, add one rule at a time, test as you go, and keep custom rules outside the WordPress markers. With the builder at the top of this page or the snippets in this guide, you can harden and optimize your site directly from a single text file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The .htaccess file is one of the most powerful configuration files on any WordPress site. This small text file sits in your site&#8217;s root folder and tells the Apache web server how to behave \u2014 handling your permalinks, forcing HTTPS, blocking attackers, speeding up your site, and setting up redirects. This guide covers everything: what [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2592,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[114,63,74],"tags":[],"class_list":["post-2589","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-other-tutorials","category-security","category-seo"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>WordPress .htaccess Generator, Default Code and Snippets - Copahost<\/title>\n<meta name=\"description\" content=\"Build a complete WordPress .htaccess with the default block, security rules, compression and caching, or check your own. Plus tested snippets.\" \/>\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.copahost.com\/blog\/htaccess\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WordPress .htaccess Generator, Default Code and Snippets - Copahost\" \/>\n<meta property=\"og:description\" content=\"Build a complete WordPress .htaccess with the default block, security rules, compression and caching, or check your own. Plus tested snippets.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.copahost.com\/blog\/htaccess\/\" \/>\n<meta property=\"og:site_name\" content=\"Copahost\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-01T13:49:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-13T12:46:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2020\/07\/Htaccess-Learn-everything-about-this-file.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1120\" \/>\n\t<meta property=\"og:image:height\" content=\"440\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Gustavo Gallas\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Gustavo Gallas\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/\"},\"author\":{\"name\":\"Gustavo Gallas\",\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/#\\\/schema\\\/person\\\/386b3f1f79299d43f4ceb33d26428246\"},\"headline\":\"WordPress .htaccess Generator, Default Code and Snippets\",\"datePublished\":\"2020-10-01T13:49:07+00:00\",\"dateModified\":\"2026-10-13T12:46:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/\"},\"wordCount\":1613,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Htaccess-Learn-everything-about-this-file.png\",\"articleSection\":[\"Other tutorials\",\"Security\",\"SEO\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/\",\"url\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/\",\"name\":\"WordPress .htaccess Generator, Default Code and Snippets - Copahost\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Htaccess-Learn-everything-about-this-file.png\",\"datePublished\":\"2020-10-01T13:49:07+00:00\",\"dateModified\":\"2026-10-13T12:46:27+00:00\",\"description\":\"Build a complete WordPress .htaccess with the default block, security rules, compression and caching, or check your own. Plus tested snippets.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Htaccess-Learn-everything-about-this-file.png\",\"contentUrl\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/Htaccess-Learn-everything-about-this-file.png\",\"width\":1120,\"height\":440,\"caption\":\"Htaccess Learn everything about this file\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/htaccess\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WordPress .htaccess Generator, Default Code and Snippets\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/\",\"name\":\"Copahost\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/#organization\",\"name\":\"Copahost\",\"url\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/03\\\/copahostlogo.png\",\"contentUrl\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/03\\\/copahostlogo.png\",\"width\":223,\"height\":40,\"caption\":\"Copahost\"},\"image\":{\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/#\\\/schema\\\/person\\\/386b3f1f79299d43f4ceb33d26428246\",\"name\":\"Gustavo Gallas\",\"description\":\"Graduated in Computing at PUC-Rio, Brazil. Specialized in IT, networking, systems administration and human and organizational development\u200b. Also have brewing skills.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/gustavo-gallas-107926196\\\/\"],\"url\":\"https:\\\/\\\/www.copahost.com\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WordPress .htaccess Generator, Default Code and Snippets - Copahost","description":"Build a complete WordPress .htaccess with the default block, security rules, compression and caching, or check your own. Plus tested snippets.","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.copahost.com\/blog\/htaccess\/","og_locale":"en_US","og_type":"article","og_title":"WordPress .htaccess Generator, Default Code and Snippets - Copahost","og_description":"Build a complete WordPress .htaccess with the default block, security rules, compression and caching, or check your own. Plus tested snippets.","og_url":"https:\/\/www.copahost.com\/blog\/htaccess\/","og_site_name":"Copahost","article_published_time":"2020-10-01T13:49:07+00:00","article_modified_time":"2026-10-13T12:46:27+00:00","og_image":[{"width":1120,"height":440,"url":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2020\/07\/Htaccess-Learn-everything-about-this-file.png","type":"image\/png"}],"author":"Gustavo Gallas","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Gustavo Gallas","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.copahost.com\/blog\/htaccess\/#article","isPartOf":{"@id":"https:\/\/www.copahost.com\/blog\/htaccess\/"},"author":{"name":"Gustavo Gallas","@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/386b3f1f79299d43f4ceb33d26428246"},"headline":"WordPress .htaccess Generator, Default Code and Snippets","datePublished":"2020-10-01T13:49:07+00:00","dateModified":"2026-10-13T12:46:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.copahost.com\/blog\/htaccess\/"},"wordCount":1613,"commentCount":0,"publisher":{"@id":"https:\/\/www.copahost.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.copahost.com\/blog\/htaccess\/#primaryimage"},"thumbnailUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2020\/07\/Htaccess-Learn-everything-about-this-file.png","articleSection":["Other tutorials","Security","SEO"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.copahost.com\/blog\/htaccess\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.copahost.com\/blog\/htaccess\/","url":"https:\/\/www.copahost.com\/blog\/htaccess\/","name":"WordPress .htaccess Generator, Default Code and Snippets - Copahost","isPartOf":{"@id":"https:\/\/www.copahost.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.copahost.com\/blog\/htaccess\/#primaryimage"},"image":{"@id":"https:\/\/www.copahost.com\/blog\/htaccess\/#primaryimage"},"thumbnailUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2020\/07\/Htaccess-Learn-everything-about-this-file.png","datePublished":"2020-10-01T13:49:07+00:00","dateModified":"2026-10-13T12:46:27+00:00","description":"Build a complete WordPress .htaccess with the default block, security rules, compression and caching, or check your own. Plus tested snippets.","breadcrumb":{"@id":"https:\/\/www.copahost.com\/blog\/htaccess\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.copahost.com\/blog\/htaccess\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.copahost.com\/blog\/htaccess\/#primaryimage","url":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2020\/07\/Htaccess-Learn-everything-about-this-file.png","contentUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2020\/07\/Htaccess-Learn-everything-about-this-file.png","width":1120,"height":440,"caption":"Htaccess Learn everything about this file"},{"@type":"BreadcrumbList","@id":"https:\/\/www.copahost.com\/blog\/htaccess\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.copahost.com\/blog\/"},{"@type":"ListItem","position":2,"name":"WordPress .htaccess Generator, Default Code and Snippets"}]},{"@type":"WebSite","@id":"https:\/\/www.copahost.com\/blog\/#website","url":"https:\/\/www.copahost.com\/blog\/","name":"Copahost","description":"","publisher":{"@id":"https:\/\/www.copahost.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.copahost.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.copahost.com\/blog\/#organization","name":"Copahost","url":"https:\/\/www.copahost.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png","contentUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png","width":223,"height":40,"caption":"Copahost"},"image":{"@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/386b3f1f79299d43f4ceb33d26428246","name":"Gustavo Gallas","description":"Graduated in Computing at PUC-Rio, Brazil. Specialized in IT, networking, systems administration and human and organizational development\u200b. Also have brewing skills.","sameAs":["https:\/\/www.linkedin.com\/in\/gustavo-gallas-107926196\/"],"url":"https:\/\/www.copahost.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts\/2589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/comments?post=2589"}],"version-history":[{"count":9,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts\/2589\/revisions"}],"predecessor-version":[{"id":6734,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts\/2589\/revisions\/6734"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/media\/2592"}],"wp:attachment":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/media?parent=2589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/categories?post=2589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/tags?post=2589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}