{"id":630,"date":"2025-09-17T22:04:32","date_gmt":"2025-09-17T22:04:32","guid":{"rendered":"https:\/\/www.pofii.com\/blog\/?p=630"},"modified":"2025-09-17T22:04:58","modified_gmt":"2025-09-17T22:04:58","slug":"htaccess-redirect-recipes-www-https-and-trailing-slashes","status":"publish","type":"post","link":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/","title":{"rendered":".htaccess Redirect Recipes: WWW, HTTPS, and Trailing Slashes"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Heads-up: <code>.htaccess<\/code> works on <strong>Apache\/LiteSpeed<\/strong> (including <strong>Pofii-Tuned LiteSpeed<\/strong>). For NGINX, use server blocks instead.<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\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.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Why_redirects_matter_30_seconds\" >Why redirects matter (30 seconds)<\/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.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#How_to_test_do_this_before_and_after\" >How to test (do this before and after)<\/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.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Base_setup_put_this_at_the_top\" >Base setup (put this at the top)<\/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.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#One-hop_canonical_HTTPS_non-www_recommended\" >One-hop canonical: HTTPS + non-www (recommended)<\/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.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#One-hop_canonical_HTTPS_www\" >One-hop canonical: HTTPS + www<\/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.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Trailing_slash_policy_pick_one\" >Trailing slash policy (pick one)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#A_Add_trailing_slash_directoriesvirtual_paths_only\" >A) Add trailing slash (directories\/virtual paths only)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#B_Remove_trailing_slash\" >B) Remove trailing slash<\/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.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#WordPress_placement_important\" >WordPress placement (important)<\/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.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Exceptions_and_gotchas_copy_if_you_need\" >Exceptions and gotchas (copy if you need)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Skip_redirects_for_static_files_and_APIs\" >Skip redirects for static files and APIs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Subfolder_installs_eg_site_in_blog\" >Subfolder installs (e.g., site in \/blog)<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Cloudflare_proxy_notes_avoid_loops\" >Cloudflare \/ proxy notes (avoid loops)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Common_one-liners_paste_and_go\" >Common one-liners (paste and go)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Force_HTTPS_only_keep_host_as-is\" >Force HTTPS only (keep host as-is)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Force_non-www_only_any_scheme\" >Force non-www only (any scheme)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Force_www_only_any_scheme\" >Force www only (any scheme)<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Minimal_checklist_2_minutes\" >Minimal checklist (2 minutes)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#FAQ\" >FAQ<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Will_these_rules_break_my_admin_or_checkout\" >Will these rules break my admin or checkout?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Do_I_need_302_or_301\" >Do I need 302 or 301?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#Can_I_combine_HTTPS_non-www_slash_in_one_rule\" >Can I combine HTTPS + non-www + slash in one rule?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#What_about_performance\" >What about performance?<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-why-redirects-matter-30-seconds\"><span class=\"ez-toc-section\" id=\"Why_redirects_matter_30_seconds\"><\/span>Why redirects matter (30 seconds)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Consistency:<\/strong> one canonical URL (https + www or not + slash policy).<\/li>\n\n\n\n<li><strong>Speed:<\/strong> avoid redirect <strong>chains<\/strong> (HTTP \u2192 HTTPS \u2192 non-www).<\/li>\n\n\n\n<li><strong>SEO:<\/strong> link equity and metrics live on the canonical.<\/li>\n\n\n\n<li><strong>Logs:<\/strong> clean analytics and easier debugging.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-test-do-this-before-and-after\"><span class=\"ez-toc-section\" id=\"How_to_test_do_this_before_and_after\"><\/span>How to test (do this before and after)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In a terminal:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -I http:\/\/example.com\/page\ncurl -I https:\/\/www.example.com\/page\/\ncurl -I -L http:\/\/example.com\/page?ref=test\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You should see <strong>one 301<\/strong> to your final URL.<\/li>\n\n\n\n<li>Query strings should remain intact.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-base-setup-put-this-at-the-top\"><span class=\"ez-toc-section\" id=\"Base_setup_put_this_at_the_top\"><\/span>Base setup (put this at the top)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Enable rewriting\nRewriteEngine On\n\n# Respect proxies (Cloudflare\/ELB) to avoid loops\nRewriteCond %{HTTP:X-Forwarded-Proto} =https &#91;OR]\nRewriteCond %{HTTPS} =on\nRewriteRule ^ - &#91;E=HTTPS_ON:1]\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This marks requests as HTTPS when a proxy terminates TLS. It helps your rules decide correctly.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-one-hop-canonical-https-non-www-recommended\"><span class=\"ez-toc-section\" id=\"One-hop_canonical_HTTPS_non-www_recommended\"><\/span>One-hop canonical: <strong>HTTPS + non-www<\/strong> (recommended)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Result:<\/strong> <code>http:\/\/example.com<\/code> \u2192 <strong><code>https:\/\/example.com<\/code><\/strong> in a single 301.<br>Replace <strong>example.com<\/strong> with your domain.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On\n\n# One-hop to https + non-www\nRewriteCond %{HTTPS} !=on &#91;OR]\nRewriteCond %{HTTP_HOST} ^www\\.example\\.com$ &#91;NC]\nRewriteRule ^ https:\/\/example.com%{REQUEST_URI} &#91;R=301,L]\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-one-hop-canonical-https-www\"><span class=\"ez-toc-section\" id=\"One-hop_canonical_HTTPS_www\"><\/span>One-hop canonical: <strong>HTTPS + www<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Prefer <code>https:\/\/www.example.com<\/code>? Use this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine On\n\n# One-hop to https + www\nRewriteCond %{HTTPS} !=on &#91;OR]\nRewriteCond %{HTTP_HOST} !^www\\.example\\.com$ &#91;NC]\nRewriteRule ^ https:\/\/www.example.com%{REQUEST_URI} &#91;R=301,L]\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-trailing-slash-policy-pick-one\"><span class=\"ez-toc-section\" id=\"Trailing_slash_policy_pick_one\"><\/span>Trailing slash policy (pick one)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Consistent slashes reduce duplicates. Choose <strong>add<\/strong> or <strong>remove<\/strong>. Do this <strong>after<\/strong> your canonical (https\/www) rule.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-a-add-trailing-slash-directories-virtual-paths-only\"><span class=\"ez-toc-section\" id=\"A_Add_trailing_slash_directoriesvirtual_paths_only\"><\/span>A) <strong>Add<\/strong> trailing slash (directories\/virtual paths only)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Add slash if missing (skip real files)\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_URI} !\\.&#91;A-Za-z0-9]{2,5}$\nRewriteCond %{REQUEST_URI} !\/$\nRewriteRule ^(.+)$ https:\/\/%{HTTP_HOST}\/$1\/ &#91;R=301,L]\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-b-remove-trailing-slash\"><span class=\"ez-toc-section\" id=\"B_Remove_trailing_slash\"><\/span>B) <strong>Remove<\/strong> trailing slash<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Remove trailing slash (keep directories)\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule ^(.+)\/$ https:\/\/%{HTTP_HOST}\/$1 &#91;R=301,L]\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Tip: WordPress often prefers <strong>no slash<\/strong> on posts and <strong>slash<\/strong> on categories. Match your permalink structure.<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-wordpress-placement-important\"><span class=\"ez-toc-section\" id=\"WordPress_placement_important\"><\/span>WordPress placement (important)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Put your rules <strong>above<\/strong> the WordPress block:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Your canonical rules here (https\/www\/slash)\n\n# BEGIN WordPress\n&lt;IfModule mod_rewrite.c&gt;\nRewriteEngine On\nRewriteBase \/\nRewriteRule ^index\\.php$ - &#91;L]\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule . \/index.php &#91;L]\n&lt;\/IfModule&gt;\n# END WordPress\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This avoids WP fighting your redirects.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-exceptions-and-gotchas-copy-if-you-need\"><span class=\"ez-toc-section\" id=\"Exceptions_and_gotchas_copy_if_you_need\"><\/span>Exceptions and gotchas (copy if you need)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-skip-redirects-for-static-files-and-apis\"><span class=\"ez-toc-section\" id=\"Skip_redirects_for_static_files_and_APIs\"><\/span>Skip redirects for static files and APIs<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Before slash rules, skip known file types and API endpoints\nRewriteCond %{REQUEST_URI} \\.(css|js|png|jpg|jpeg|gif|webp|avif|svg|ico|pdf|zip)$ &#91;NC]\nRewriteRule ^ - &#91;L]\n\n# Skip REST, cron, and sitemap endpoints\nRewriteCond %{REQUEST_URI} ^\/(wp-json|wp-cron\\.php|sitemap\\.xml) &#91;NC]\nRewriteRule ^ - &#91;L]\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-subfolder-installs-e-g-site-in-blog\"><span class=\"ez-toc-section\" id=\"Subfolder_installs_eg_site_in_blog\"><\/span>Subfolder installs (e.g., site in <code>\/blog<\/code>)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Place <code>.htaccess<\/code> <strong>inside<\/strong> <code>\/blog<\/code>. Then use the same recipes.<br>If you must keep it in the root, prefix rules with <code>^blog\/\u2026<\/code> and targets with <code>\/blog\/\u2026<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cloudflare-proxy-notes-avoid-loops\"><span class=\"ez-toc-section\" id=\"Cloudflare_proxy_notes_avoid_loops\"><\/span>Cloudflare \/ proxy notes (avoid loops)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set SSL mode to <strong>Full (strict)<\/strong>. Avoid <strong>Flexible<\/strong>; origin sees HTTP and loops happen.<\/li>\n\n\n\n<li>If you force HTTPS at Cloudflare with \u201cAlways Use HTTPS,\u201d <strong>remove<\/strong> your local HTTPS rule or you\u2019ll chain. <a href=\"https:\/\/www.pofii.com\/blog\/what-is-cloudflare-and-how-to-get-maximum-out-of-it\/\">Check Cloudflare tutorial here.<\/a><\/li>\n\n\n\n<li>For Page Rules\/Cache Rules, continue to <strong>bypass<\/strong> <code>\/wp-admin<\/code> and <strong>never<\/strong> cache HTML for logged-in users.<\/li>\n\n\n\n<li>If needed, use this HTTPS detector with proxies:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteCond %{HTTPS} !=on\nRewriteCond %{HTTP:X-Forwarded-Proto} !https\nRewriteRule ^ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;R=301,L]\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-common-one-liners-paste-and-go\"><span class=\"ez-toc-section\" id=\"Common_one-liners_paste_and_go\"><\/span>Common one-liners (paste and go)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-force-https-only-keep-host-as-is\"><span class=\"ez-toc-section\" id=\"Force_HTTPS_only_keep_host_as-is\"><\/span>Force <strong>HTTPS only<\/strong> (keep host as-is)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteCond %{HTTPS} !=on\nRewriteRule ^ https:\/\/%{HTTP_HOST}%{REQUEST_URI} &#91;R=301,L]\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-force-non-www-only-any-scheme\"><span class=\"ez-toc-section\" id=\"Force_non-www_only_any_scheme\"><\/span>Force <strong>non-www only<\/strong> (any scheme)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteCond %{HTTP_HOST} ^www\\.(.+)$ &#91;NC]\nRewriteRule ^ https:\/\/%1%{REQUEST_URI} &#91;R=301,L]\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-force-www-only-any-scheme\"><span class=\"ez-toc-section\" id=\"Force_www_only_any_scheme\"><\/span>Force <strong>www only<\/strong> (any scheme)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteCond %{HTTP_HOST} !^www\\. &#91;NC]\nRewriteRule ^ https:\/\/www.%{HTTP_HOST}%{REQUEST_URI} &#91;R=301,L]\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-minimal-checklist-2-minutes\"><span class=\"ez-toc-section\" id=\"Minimal_checklist_2_minutes\"><\/span>Minimal checklist (2 minutes)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Decide canonical: <strong>https + www<\/strong> <em>or<\/em> <strong>https + non-www<\/strong><\/li>\n\n\n\n<li>Add <strong>one-hop<\/strong> canonical rule (no chains)<\/li>\n\n\n\n<li>Choose a <strong>slash<\/strong> policy and add the rule after canonical<\/li>\n\n\n\n<li>Place rules <strong>above<\/strong> the WordPress block<\/li>\n\n\n\n<li>Test with <code>curl -I<\/code> and ensure <strong>one 301<\/strong> to the final URL<\/li>\n\n\n\n<li>Verify query strings are preserved<\/li>\n\n\n\n<li>If on Cloudflare, use <strong>Full (strict)<\/strong> and avoid duplicate HTTPS forcing<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-faq\"><span class=\"ez-toc-section\" id=\"FAQ\"><\/span>FAQ<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-will-these-rules-break-my-admin-or-checkout\"><span class=\"ez-toc-section\" id=\"Will_these_rules_break_my_admin_or_checkout\"><\/span>Will these rules break my admin or checkout?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">No, not if placed above the WP block and you keep default WP rewrites. Still, test <code>\/wp-admin\/<\/code>, login, cart, and checkout after changes.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-do-i-need-302-or-301\"><span class=\"ez-toc-section\" id=\"Do_I_need_302_or_301\"><\/span>Do I need 302 or 301?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Use <strong>301<\/strong> for permanent canonicals. Use <strong>302<\/strong> only during short tests.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-can-i-combine-https-non-www-slash-in-one-rule\"><span class=\"ez-toc-section\" id=\"Can_I_combine_HTTPS_non-www_slash_in_one_rule\"><\/span>Can I combine HTTPS + non-www + slash in one rule?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, but readability suffers. The <strong>one-hop canonical<\/strong> plus a <strong>separate slash<\/strong> rule is clean and reliable.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-what-about-performance\"><span class=\"ez-toc-section\" id=\"What_about_performance\"><\/span>What about performance?<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">One decisive redirect is cheap. Avoid <strong>chains<\/strong>. On Pofii\u2019s LiteSpeed stack, these rules are evaluated quickly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You want one clean URL for every page. No chains. No loops. Just fast, canonical URLs that help SEO and users. These Apache\/LiteSpeed .htaccess recipes are safe defaults you can paste today. They also play nicely with WordPress.<\/p>\n","protected":false},"author":6,"featured_media":645,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,50],"tags":[236,238,188],"class_list":["post-630","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hosting","category-tutorials","tag-htaccess","tag-redirects","tag-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>.htaccess Redirect Recipes: WWW, HTTPS, and Trailing Slashes - Pofii Insights<\/title>\n<meta name=\"description\" content=\"Copy-paste .htaccess redirects for HTTPS, www\/non-www, and trailing slashes. Canonical URLs, no loops. Safe for WordPress &amp; LiteSpeed.\" \/>\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.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\".htaccess Redirect Recipes: WWW, HTTPS, and Trailing Slashes\" \/>\n<meta property=\"og:description\" content=\"Copy-paste .htaccess redirects for HTTPS, www\/non-www, and trailing slashes. Canonical URLs, no loops. Safe for WordPress &amp; LiteSpeed.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/\" \/>\n<meta property=\"og:site_name\" content=\"Pofii Insights\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/PofiiCOM\" \/>\n<meta property=\"article:published_time\" content=\"2025-09-17T22:04:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-17T22:04:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2025\/09\/htaccess-illustration.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Emma Collins\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@PofiiGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@PofiiGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Emma Collins\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/\"},\"author\":{\"name\":\"Emma Collins\",\"@id\":\"https:\/\/www.pofii.com\/blog\/#\/schema\/person\/08fd66a92336acf35289e93b5c6e4cec\"},\"headline\":\".htaccess Redirect Recipes: WWW, HTTPS, and Trailing Slashes\",\"datePublished\":\"2025-09-17T22:04:32+00:00\",\"dateModified\":\"2025-09-17T22:04:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/\"},\"wordCount\":465,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pofii.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2025\/09\/htaccess-illustration.png\",\"keywords\":[\".htaccess\",\"Redirects\",\"WordPress\"],\"articleSection\":[\"Hosting Tips &amp; Tricks\",\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/\",\"url\":\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/\",\"name\":\".htaccess Redirect Recipes: WWW, HTTPS, and Trailing Slashes - Pofii Insights\",\"isPartOf\":{\"@id\":\"https:\/\/www.pofii.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2025\/09\/htaccess-illustration.png\",\"datePublished\":\"2025-09-17T22:04:32+00:00\",\"dateModified\":\"2025-09-17T22:04:58+00:00\",\"description\":\"Copy-paste .htaccess redirects for HTTPS, www\/non-www, and trailing slashes. Canonical URLs, no loops. Safe for WordPress & LiteSpeed.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#primaryimage\",\"url\":\"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2025\/09\/htaccess-illustration.png\",\"contentUrl\":\"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2025\/09\/htaccess-illustration.png\",\"width\":1280,\"height\":720},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/nl.pofii.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\".htaccess Redirect Recipes: WWW, HTTPS, and Trailing Slashes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pofii.com\/blog\/#website\",\"url\":\"https:\/\/www.pofii.com\/blog\/\",\"name\":\"Pofii\",\"description\":\"Success Simplified.\",\"publisher\":{\"@id\":\"https:\/\/www.pofii.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pofii.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pofii.com\/blog\/#organization\",\"name\":\"Pofii\",\"url\":\"https:\/\/www.pofii.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pofii.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2024\/12\/cropped-cropped-pofiiinsights-2.png\",\"contentUrl\":\"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2024\/12\/cropped-cropped-pofiiinsights-2.png\",\"width\":2079,\"height\":221,\"caption\":\"Pofii\"},\"image\":{\"@id\":\"https:\/\/www.pofii.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/PofiiCOM\",\"https:\/\/x.com\/PofiiGlobal\",\"https:\/\/www.instagram.com\/PofiiGlobal\",\"https:\/\/www.linkedin.com\/company\/Pofii\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pofii.com\/blog\/#\/schema\/person\/08fd66a92336acf35289e93b5c6e4cec\",\"name\":\"Emma Collins\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pofii.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.pofii.com\/brand\/logo-icon-circle-friendly.png\",\"contentUrl\":\"https:\/\/www.pofii.com\/brand\/logo-icon-circle-friendly.png\",\"caption\":\"Emma Collins\"},\"sameAs\":[\"https:\/\/www.pofii.com\/blog\/author\/EmmaC\"],\"gender\":\"female\",\"knowsLanguage\":[\"English\"],\"worksFor\":\"Pofii Ltd.\",\"url\":\"https:\/\/www.pofii.com\/blog\/author\/emmac\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":".htaccess Redirect Recipes: WWW, HTTPS, and Trailing Slashes - Pofii Insights","description":"Copy-paste .htaccess redirects for HTTPS, www\/non-www, and trailing slashes. Canonical URLs, no loops. Safe for WordPress & LiteSpeed.","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.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/","og_locale":"en_US","og_type":"article","og_title":".htaccess Redirect Recipes: WWW, HTTPS, and Trailing Slashes","og_description":"Copy-paste .htaccess redirects for HTTPS, www\/non-www, and trailing slashes. Canonical URLs, no loops. Safe for WordPress & LiteSpeed.","og_url":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/","og_site_name":"Pofii Insights","article_publisher":"https:\/\/www.facebook.com\/PofiiCOM","article_published_time":"2025-09-17T22:04:32+00:00","article_modified_time":"2025-09-17T22:04:58+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2025\/09\/htaccess-illustration.png","type":"image\/png"}],"author":"Emma Collins","twitter_card":"summary_large_image","twitter_creator":"@PofiiGlobal","twitter_site":"@PofiiGlobal","twitter_misc":{"Written by":"Emma Collins","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#article","isPartOf":{"@id":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/"},"author":{"name":"Emma Collins","@id":"https:\/\/www.pofii.com\/blog\/#\/schema\/person\/08fd66a92336acf35289e93b5c6e4cec"},"headline":".htaccess Redirect Recipes: WWW, HTTPS, and Trailing Slashes","datePublished":"2025-09-17T22:04:32+00:00","dateModified":"2025-09-17T22:04:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/"},"wordCount":465,"commentCount":0,"publisher":{"@id":"https:\/\/www.pofii.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2025\/09\/htaccess-illustration.png","keywords":[".htaccess","Redirects","WordPress"],"articleSection":["Hosting Tips &amp; Tricks","Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/","url":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/","name":".htaccess Redirect Recipes: WWW, HTTPS, and Trailing Slashes - Pofii Insights","isPartOf":{"@id":"https:\/\/www.pofii.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#primaryimage"},"image":{"@id":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2025\/09\/htaccess-illustration.png","datePublished":"2025-09-17T22:04:32+00:00","dateModified":"2025-09-17T22:04:58+00:00","description":"Copy-paste .htaccess redirects for HTTPS, www\/non-www, and trailing slashes. Canonical URLs, no loops. Safe for WordPress & LiteSpeed.","breadcrumb":{"@id":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#primaryimage","url":"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2025\/09\/htaccess-illustration.png","contentUrl":"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2025\/09\/htaccess-illustration.png","width":1280,"height":720},{"@type":"BreadcrumbList","@id":"https:\/\/www.pofii.com\/blog\/htaccess-redirect-recipes-www-https-and-trailing-slashes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nl.pofii.com\/blog\/"},{"@type":"ListItem","position":2,"name":".htaccess Redirect Recipes: WWW, HTTPS, and Trailing Slashes"}]},{"@type":"WebSite","@id":"https:\/\/www.pofii.com\/blog\/#website","url":"https:\/\/www.pofii.com\/blog\/","name":"Pofii","description":"Success Simplified.","publisher":{"@id":"https:\/\/www.pofii.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pofii.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pofii.com\/blog\/#organization","name":"Pofii","url":"https:\/\/www.pofii.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pofii.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2024\/12\/cropped-cropped-pofiiinsights-2.png","contentUrl":"https:\/\/www.pofii.com\/blog\/wp-content\/uploads\/2024\/12\/cropped-cropped-pofiiinsights-2.png","width":2079,"height":221,"caption":"Pofii"},"image":{"@id":"https:\/\/www.pofii.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/PofiiCOM","https:\/\/x.com\/PofiiGlobal","https:\/\/www.instagram.com\/PofiiGlobal","https:\/\/www.linkedin.com\/company\/Pofii"]},{"@type":"Person","@id":"https:\/\/www.pofii.com\/blog\/#\/schema\/person\/08fd66a92336acf35289e93b5c6e4cec","name":"Emma Collins","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pofii.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/www.pofii.com\/brand\/logo-icon-circle-friendly.png","contentUrl":"https:\/\/www.pofii.com\/brand\/logo-icon-circle-friendly.png","caption":"Emma Collins"},"sameAs":["https:\/\/www.pofii.com\/blog\/author\/EmmaC"],"gender":"female","knowsLanguage":["English"],"worksFor":"Pofii Ltd.","url":"https:\/\/www.pofii.com\/blog\/author\/emmac\/"}]}},"_links":{"self":[{"href":"https:\/\/www.pofii.com\/blog\/wp-json\/wp\/v2\/posts\/630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pofii.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pofii.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pofii.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pofii.com\/blog\/wp-json\/wp\/v2\/comments?post=630"}],"version-history":[{"count":4,"href":"https:\/\/www.pofii.com\/blog\/wp-json\/wp\/v2\/posts\/630\/revisions"}],"predecessor-version":[{"id":689,"href":"https:\/\/www.pofii.com\/blog\/wp-json\/wp\/v2\/posts\/630\/revisions\/689"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pofii.com\/blog\/wp-json\/wp\/v2\/media\/645"}],"wp:attachment":[{"href":"https:\/\/www.pofii.com\/blog\/wp-json\/wp\/v2\/media?parent=630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pofii.com\/blog\/wp-json\/wp\/v2\/categories?post=630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pofii.com\/blog\/wp-json\/wp\/v2\/tags?post=630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}