{"id":780,"date":"2024-10-11T16:12:49","date_gmt":"2024-10-11T16:12:49","guid":{"rendered":"https:\/\/breakui.com\/?p=780"},"modified":"2026-09-04T15:05:03","modified_gmt":"2026-09-04T15:05:03","slug":"how-to-redirect-non-www-to-www-urls-in-wordpress","status":"publish","type":"post","link":"https:\/\/breakui.com\/how-to-redirect-non-www-to-www-urls-in-wordpress\/","title":{"rendered":"How to Redirect Non-www to www URLs in WordPress"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hey, <a href=\"https:\/\/monir.website\/\" data-type=\"link\" data-id=\"https:\/\/monir.website\/\" target=\"_blank\" rel=\"noopener\">Monir<\/a> here from Breakui! Today, I\u2019m going to help you solve a common problem many website owners how to redirect non-www URLs to www URLs in WordPress. If you&#8217;re running a website and want everything to go to the www version of your domain (because, let\u2019s be honest, it just looks cooler and sometimes helps with SEO), I\u2019ve got you covered!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let me explain the process in a simple way, so anyone can do it. We\u2019ll be doing this by adding some code to two important files: the <code>.htaccess<\/code> file and the <code>wp-config.php<\/code> file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why Should You Redirect Non-www to www?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before we get into the technical stuff, let me explain <strong>why<\/strong> you\u2019d want to do this.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Consistency<\/strong>: Having both www and non-www versions can confuse search engines. You want to make sure all traffic goes to one version to avoid duplicate content issues.<\/li>\n\n\n\n<li><strong>Branding<\/strong>: Some people just like how the www looks. It\u2019s more official and traditional.<\/li>\n\n\n\n<li><strong>SEO<\/strong>: Search engines treat www and non-www as two different websites. Redirecting helps ensure that all your traffic goes to the same place, which can help your SEO rankings.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Editing Your <code>.htaccess<\/code> File<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Your <a href=\"https:\/\/developer.wordpress.org\/advanced-administration\/server\/web-server\/httpd\/\" data-type=\"link\" data-id=\"https:\/\/developer.wordpress.org\/advanced-administration\/server\/web-server\/httpd\/\" target=\"_blank\" rel=\"noopener\"><code>.htaccess<\/code> file<\/a> controls many important settings in your WordPress site, including URL redirections. This file is usually located in the root folder of your WordPress installation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s the code you need to add after <code>RewriteEngine On<\/code>:<br><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>RewriteCond %{HTTP_HOST} ^yoursite\\.com &#91;NC&#93;\nRewriteRule ^(.*)$ https:\/\/www.yoursite.com\/$1 &#91;L,R=301&#93;<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6CB6FF\">RewriteCond<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F47067\">%<\/span><span style=\"color: #ADBAC7\">{<\/span><span style=\"color: #6CB6FF\">HTTP_HOST<\/span><span style=\"color: #ADBAC7\">} <\/span><span style=\"color: #F47067\">^<\/span><span style=\"color: #6CB6FF\">yoursite<\/span><span style=\"color: #ADBAC7\">\\<\/span><span style=\"color: #F47067\">.<\/span><span style=\"color: #6CB6FF\">com<\/span><span style=\"color: #ADBAC7\"> &#91;<\/span><span style=\"color: #6CB6FF\">NC<\/span><span style=\"color: #ADBAC7\">&#93;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6CB6FF\">RewriteRule<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F47067\">^<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #F47067\">.<\/span><span style=\"color: #F47067\">*<\/span><span style=\"color: #ADBAC7\">)$ <\/span><span style=\"color: #6CB6FF\">https<\/span><span style=\"color: #ADBAC7\">:<\/span><span style=\"color: #768390\">\/\/www.yoursite.com\/$1 &#91;L,R=301&#93;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This code basically says, \u201cHey, if someone tries to visit the non-www version of my site, redirect them to the www version!\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Where to add this?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open your <code>.htaccess<\/code> file.<\/li>\n\n\n\n<li>Look for the line that says <code>RewriteEngine On<\/code>.<\/li>\n\n\n\n<li>Paste the code <strong>right after<\/strong> that line.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Editing the <code>wp-config.php<\/code> File<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now, we need to make sure WordPress also knows we want to use the www version for everything. For that, we\u2019ll edit the <code>wp-config.php<\/code> file, which is also in the root folder of your WordPress installation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s what you need to add:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#22272e\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>define('WP_HOME','https:\/\/www.yoursite.com');\ndefine('WP_SITEURL','https:\/\/www.yoursite.com');<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6CB6FF\">define<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #96D0FF\">&#39;WP_HOME&#39;<\/span><span style=\"color: #ADBAC7\">,<\/span><span style=\"color: #96D0FF\">&#39;https:\/\/www.yoursite.com&#39;<\/span><span style=\"color: #ADBAC7\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6CB6FF\">define<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #96D0FF\">&#39;WP_SITEURL&#39;<\/span><span style=\"color: #ADBAC7\">,<\/span><span style=\"color: #96D0FF\">&#39;https:\/\/www.yoursite.com&#39;<\/span><span style=\"color: #ADBAC7\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What does this do?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>These two lines tell WordPress to always load the www version of your site, whether it\u2019s on the backend or frontend.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>How to do it:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open your <code>wp-config.php<\/code> file.\n<ul class=\"wp-block-list\">\n<li>Find a safe spot (usually after the database settings).<img loading=\"lazy\" decoding=\"async\" width=\"350\" height=\"89\" class=\"wp-image-784\" style=\"width: 350px;\" src=\"https:\/\/breakui.com\/wp-content\/uploads\/2024\/10\/non-www-to-www.png\" alt=\"\" srcset=\"https:\/\/breakui.com\/wp-content\/uploads\/2024\/10\/non-www-to-www.png 1042w, https:\/\/breakui.com\/wp-content\/uploads\/2024\/10\/non-www-to-www-300x77.png 300w, https:\/\/breakui.com\/wp-content\/uploads\/2024\/10\/non-www-to-www-1024x261.png 1024w, https:\/\/breakui.com\/wp-content\/uploads\/2024\/10\/non-www-to-www-768x196.png 768w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Paste the code.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Test Your Website<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After adding these codes, go to your browser and try typing your non-www domain, like <code>http:\/\/yoursite.com<\/code>. If everything is set up properly, it should automatically take you to <code>https:\/\/www.yoursite.com<\/code>. If not, double-check your <code>.htaccess<\/code> and <code>wp-config.php<\/code> files for any typos.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-text-align-center\">FAQs on Redirecting Non-www to www URLs in WordPress<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Why should I redirect non-www to www in WordPress?<\/strong><br>Redirecting helps create consistency for your users and search engines. It ensures that all traffic is directed to one version of your site, improving your SEO and avoiding duplicate content issues. Plus, it just makes your site look more professional!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. Will this affect my SEO?<\/strong><br>Yes, in a positive way! When search engines see all your traffic going to the www version, they rank your site better because you&#8217;re not splitting traffic between two URLs. This improves your overall SEO strategy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Can I redirect using a plugin instead of editing files?<\/strong><br>Yes, you can use plugins like Redirection or All-in-One SEO, but manually editing the <code>.htaccess<\/code> and <code>wp-config.php<\/code> files gives you more control and reduces dependency on plugins.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. Is it safe to modify the <code>.htaccess<\/code> and <code>wp-config.php<\/code> files?<\/strong><br>Yes, but make sure you create a backup before making any changes. A small mistake in these files could cause issues, but if you follow the steps carefully, you\u2019ll be fine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5. Can this method be used for any type of website, or just WordPress?<\/strong><br>This guide is specifically for WordPress, but the <code>.htaccess<\/code> method works for any website that runs on Apache servers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Final Thoughts<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it! You\u2019ve successfully redirected your non-www URLs to www in WordPress. By doing this, you\u2019ve improved your site&#8217;s branding and SEO, and you\u2019re giving your visitors a more consistent experience.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hope this guide helps you set up your website properly. And if you\u2019re still confused, feel free to reach out for help. We\u2019re always happy to help each other out, right?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Good luck with your website journey, and stay tuned for more tips!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Monir here from Breakui! Today, I\u2019m going to help you solve a common problem many website owners how to redirect non-www URLs to www URLs in WordPress. If you&#8217;re running a website and want everything to go to the www version of your domain (because, let\u2019s be honest, it just looks cooler and sometimes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":796,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_breakdance_hide_in_design_set":false,"_breakdance_tags":"","footnotes":""},"categories":[13],"tags":[],"class_list":["post-780","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress-tips"],"acf":[],"_links":{"self":[{"href":"https:\/\/breakui.com\/wp-json\/wp\/v2\/posts\/780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/breakui.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/breakui.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/breakui.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/breakui.com\/wp-json\/wp\/v2\/comments?post=780"}],"version-history":[{"count":0,"href":"https:\/\/breakui.com\/wp-json\/wp\/v2\/posts\/780\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/breakui.com\/wp-json\/wp\/v2\/media\/796"}],"wp:attachment":[{"href":"https:\/\/breakui.com\/wp-json\/wp\/v2\/media?parent=780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/breakui.com\/wp-json\/wp\/v2\/categories?post=780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/breakui.com\/wp-json\/wp\/v2\/tags?post=780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}