{"id":2262,"date":"2025-07-11T09:25:42","date_gmt":"2025-07-11T09:25:42","guid":{"rendered":"https:\/\/hostrago.com\/knowledge-base\/?p=2262"},"modified":"2025-07-11T09:25:44","modified_gmt":"2025-07-11T09:25:44","slug":"redirect-www-or-non-www-urls-htaccess-cpanel","status":"publish","type":"post","link":"https:\/\/hostrago.com\/knowledge-base\/redirect-www-or-non-www-urls-htaccess-cpanel\/","title":{"rendered":"How to Redirect www or Non-www URLs with .htaccess via cPanel?"},"content":{"rendered":"\n<p>Whether you&#8217;re hosting with us at <a class=\"\" href=\"https:\/\/hostrago.com\/\">Hostrago<\/a>, or using another provider, applying a proper <strong>Redirect www or Non-www URLs<\/strong> strategy is key to search engine optimization and professional site management. Let\u2019s dive into the process and secure your domain structure the right way.<\/p>\n\n\n\n<p>When managing a website, <strong>domain consistency<\/strong> is crucial for SEO and user experience. One common issue many website owners face is handling both the <code>www<\/code> and <code>non-www<\/code> versions of their site. Without proper redirection, search engines may treat these as two separate websites, causing <strong>duplicate content issues<\/strong>. In this blog, you\u2019ll learn <strong>how to redirect www or non-www URLs using the .htaccess file via cPanel<\/strong>, ensuring your site runs with a <strong>single canonical domain version<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Should You Redirect www or Non-www URLs?<\/h2>\n\n\n\n<p>Redirection is more than just a technical step\u2014it\u2019s a strategic move to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Improve SEO ranking<\/strong> by avoiding duplicate content.<\/li>\n\n\n\n<li><strong>Maintain consistent branding<\/strong> across all marketing platforms.<\/li>\n\n\n\n<li><strong>Enhance user experience<\/strong> by avoiding confusion or broken links.<\/li>\n\n\n\n<li><strong>Strengthen link juice<\/strong> by consolidating backlinks to one version.<\/li>\n<\/ul>\n\n\n\n<p>Most search engines prefer one version of your website. You can choose to keep either the <strong>www<\/strong> or the <strong>non-www<\/strong> version active, and redirect the other.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Before starting, make sure:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Your website is hosted on <strong>Apache server<\/strong> (common in shared hosting).<\/li>\n\n\n\n<li>You have access to your hosting <strong>cPanel<\/strong>.<\/li>\n\n\n\n<li>You can locate and edit your site&#8217;s <strong>.htaccess file<\/strong> (usually in the root <code>\/public_html\/<\/code> directory).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Redirect www to non-www (or vice versa) via .htaccess in cPanel<\/h2>\n\n\n\n<p>Follow these simple steps to implement redirection using <code>.htaccess<\/code>:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Log in to cPanel<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go to your hosting provider\u2019s <strong><a href=\"https:\/\/cpanel.net\/\" target=\"_blank\" rel=\"noopener\">cPanel <\/a>login page<\/strong>.<\/li>\n\n\n\n<li>Enter your <strong>username<\/strong> and <strong>password<\/strong> to access the dashboard.<\/li>\n<\/ul>\n\n\n\n<p>\ud83d\udfe2 <em>Hostrago clients can log in via <a>this portal<\/a><\/em>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Open File Manager<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Inside cPanel, scroll to the <strong>Files<\/strong> section and click on <strong>File Manager<\/strong>.<\/li>\n\n\n\n<li>Navigate to your website&#8217;s root directory, usually <code>\/public_html<\/code>.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"687\" src=\"https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/07\/Open-File-Manager-1024x687.webp\" loading=\"lazy\" alt=\"Open File Manager\" class=\"wp-image-2265\" srcset=\"https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/07\/Open-File-Manager-1024x687.webp 1024w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/07\/Open-File-Manager-300x201.webp 300w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/07\/Open-File-Manager-768x515.webp 768w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/07\/Open-File-Manager-1536x1030.webp 1536w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/07\/Open-File-Manager-2048x1373.webp 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Locate and Edit the .htaccess File<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Look for the <code>.htaccess<\/code> file.<\/li>\n\n\n\n<li>If it&#8217;s not visible, click on <strong>Settings<\/strong> (top right corner) and enable <strong>Show Hidden Files<\/strong>.<\/li>\n\n\n\n<li>Right-click on <code>.htaccess<\/code> \u2192 <strong>Edit<\/strong>.<\/li>\n<\/ul>\n\n\n\n<p>\u26a0\ufe0f <strong>Note:<\/strong> Backup your <code>.htaccess<\/code> before making changes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"458\" src=\"https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/07\/Locate-and-Edit-the-.htaccess-File-1024x458.webp\" loading=\"lazy\" alt=\"Locate and Edit the .htaccess File\" class=\"wp-image-2264\" srcset=\"https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/07\/Locate-and-Edit-the-.htaccess-File-1024x458.webp 1024w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/07\/Locate-and-Edit-the-.htaccess-File-300x134.webp 300w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/07\/Locate-and-Edit-the-.htaccess-File-768x343.webp 768w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/07\/Locate-and-Edit-the-.htaccess-File-1536x687.webp 1536w, https:\/\/hostrago.com\/knowledge-base\/wp-content\/uploads\/2025\/07\/Locate-and-Edit-the-.htaccess-File-2048x916.webp 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Redirect from www to non-www<\/h3>\n\n\n\n<p>Paste the following code into the top of your <code>.htaccess<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>RewriteEngine On  <br>RewriteCond %{HTTP_HOST} ^www\\.yourdomain\\.com [NC]  <br>RewriteRule ^(.*)$ https:\/\/yourdomain.com\/$1 [L,R=301]<br><\/code><\/pre>\n\n\n\n<p>Replace <code>yourdomain.com<\/code> with your actual domain name.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Redirect from non-www to www<\/h3>\n\n\n\n<p>Alternatively, use this code if you want to redirect the <strong>non-www<\/strong> version to the <strong>www<\/strong> version:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>RewriteEngine On  <br>RewriteCond %{HTTP_HOST} ^yourdomain\\.com [NC]  <br>RewriteRule ^(.*)$ https:\/\/www.yourdomain.com\/$1 [L,R=301]<br><\/code><\/pre>\n\n\n\n<p>Again, change <code>yourdomain.com<\/code> to your own domain.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Issues &amp; Troubleshooting<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If your site stops working, double-check for typos in the <code>.htaccess<\/code> code.<\/li>\n\n\n\n<li>Ensure the <strong>mod_rewrite<\/strong> module is enabled on your server.<\/li>\n\n\n\n<li>Clear your browser\u2019s cache before testing.<\/li>\n<\/ul>\n\n\n\n<p>Need expert help? <a href=\"https:\/\/hostrago.com\/contact-us\/\">Contact Hostrago Support<\/a> \u2014 our team is always ready to assist.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Choosing between Redirect www or Non-www URLs is a small but significant decision. It\u2019s not about which one is better, but about <strong>consistency<\/strong>. By learning how to Redirect www or Non-www URLs, you take control of your domain structure, SEO credibility, and user experience.<\/p>\n\n\n\n<p>Whether you&#8217;re running a personal blog or a growing business, following this redirection strategy is essential. And if you&#8217;re hosting with <a class=\"\" href=\"https:\/\/hostrago.com\">Hostrago<\/a>, we\u2019ve got all the tools you need to manage these settings smoothly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Need Help With Your Hosting Setup?<\/strong><\/h3>\n\n\n\n<p>Explore our <a href=\"https:\/\/hostrago.com\/cloud-hosting\/\">cPanel Hosting Plans<\/a> or contact our support for <strong>free assistance<\/strong> with redirection, DNS settings, and more.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whether you&#8217;re hosting with us at Hostrago, or using another provider, applying a proper Redirect www or Non-www URLs strategy is key to search engine&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2263,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[546,547,543,548,545,544,130],"class_list":["post-2262","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpanel","tag-htaccess-redirect","tag-canonical-domain-redirect","tag-cpanel-redirect","tag-hostrago-blog","tag-redirect-www-or-non-www-urls","tag-seo-redirection","tag-web-hosting-tips"],"menu_order":0,"_links":{"self":[{"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/2262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=2262"}],"version-history":[{"count":1,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/2262\/revisions"}],"predecessor-version":[{"id":2267,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/2262\/revisions\/2267"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/media\/2263"}],"wp:attachment":[{"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=2262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=2262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostrago.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=2262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}