{"id":12160,"date":"2021-10-28T10:08:04","date_gmt":"2021-10-28T10:08:04","guid":{"rendered":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?p=12160"},"modified":"2025-05-30T12:53:43","modified_gmt":"2025-05-30T11:53:43","slug":"how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel","status":"publish","type":"post","link":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/","title":{"rendered":"How to Redirect www or Non-www URLs with .htaccess via cPanel?"},"content":{"rendered":"<p>You can force the users to divert from the\u00a0www to non-www URL and vice-versa for your domain. As a cPanel user, you can add a directive to redirect from www to non-www URLs or the other way in the .htaccess file.<\/p>\n<h2>To Redirect www to Non-www URLs with .htaccess<\/h2>\n<p>1. Log in to your cPanel account.<\/p>\n<p>2. Create\/edit <strong>.htaccess<\/strong> file in the document root of your domain via <em>File Manager<\/em>.<\/p>\n<p>You can refer to the article: <a href=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-edit-a-htaccess-file-through-the-cpanel-file-manager\/\">How To Edit A .htaccess File Through The cPanel File Manager?<\/a><\/p>\n<p>3. Add this code at the end of the file:<\/p>\n<pre class=\"font-size:15 line-height:20 lang:default decode:true\"># Redirect www URLs to non-www URLs - like http:\/\/www.yourdomain.com to http:\/\/yourdomain.com\nRewriteEngine on\nRewriteCond %{HTTP_HOST} ^www\\.yourdomain\\.com [NC]\nRewriteRule (.*) http:\/\/yourdomain.com\/$1 [R=301,L]<\/pre>\n<p>4. Click on <strong>Save Changes<\/strong> and <strong>Close<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13647\" src=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2021\/10\/cp_redirect_www-non_www_htaccess.jpg\" alt=\"\" width=\"1599\" height=\"544\" \/><\/p>\n<h2>To Redirect Non-www to www URLs with .htaccess<\/h2>\n<p>1. Log in to your cPanel account.<\/p>\n<p>2. Create\/edit <strong>.htaccess<\/strong> file in the document root of your domain via <em>File Manager<\/em>.<\/p>\n<p>3. Add this code at the end of the file:<\/p>\n<pre class=\"font-size:15 line-height:20 lang:default decode:true\"># Redirect non-www URLs to www URLs - like http:\/\/yourdomain.com to http:\/\/www.yourdomain.com\nRewriteEngine on\nRewriteCond %{HTTP_HOST} !^www\\.yourdomain\\.com [NC]\nRewriteRule (.*) http:\/\/www.yourdomain.com\/$1 [R=301,L]<\/pre>\n<p>4. Click on <strong>Save Changes<\/strong> and <strong>Close<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13646\" src=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2021\/10\/cp_redirect_non_www-www_htaccess.jpg\" alt=\"\" width=\"1599\" height=\"561\" \/><\/p>\n<div class=\"kb-wisdom-wrapr kb-wisdom-key kb-wisdom-wrapr-green\">\n<div class=\"kb-wisdom-col kb-wisdom-col-icon\">\n<div class=\"kb-wisdom-icon\">\n<div><\/div>\n<\/div>\n<\/div>\n<div class=\"kb-wisdom-col kb-wisdom-col-content\">\n<p><strong>Note<\/strong>: If a redirection directive is already mentioned in the .htaccess file, you will have to replace it to change the redirection target.<\/p>\n<\/div>\n<\/div>\n<p>Here&#8217;s an example of how the non-www to www URLs redirect will function after configuring the .htaccess file in cPanel:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13658\" src=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2021\/10\/cp_redirect_non_www-www_example.jpg\" alt=\"\" width=\"1436\" height=\"115\" \/><\/p>\n<p><strong>Redirects to:<\/strong><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13657\" src=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2021\/10\/cp_redirect_non_www-www_example2.jpg\" alt=\"\" width=\"1433\" height=\"645\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can force the users to divert from the\u00a0www to non-www URL and vice-versa for your domain. As a cPanel user, you can add a directive to redirect from www to non-www URLs or the other way in the .htaccess file. To Redirect www to Non-www URLs with .htaccess 1. Log in to your cPanel [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,41],"tags":[1725,1723,2614,1228,1724],"class_list":["post-12160","post","type-post","status-publish","format-standard","placeholder-for-hentry","category-cpanel-faq","category-howtos","tag-cpanel-url-redirect","tag-create-url-redirect-from-cpanel","tag-non-www-urls-htaccess-cpanel","tag-redirect-urls","tag-url-redirect"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Redirect www or Non-www URLs with .htaccess via cPanel?<\/title>\n<meta name=\"description\" content=\"This guide describes the process to redirect www to non-www URLs and vice-versa for your domain using the .htaccess file from cPanel.\" \/>\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.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Redirect www or Non-www URLs with .htaccess via cPanel?\" \/>\n<meta property=\"og:description\" content=\"This guide describes the process to redirect www to non-www URLs and vice-versa for your domain using the .htaccess file from cPanel.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Hosting FAQs by MilesWeb\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-28T10:08:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-30T11:53:43+00:00\" \/>\n<meta name=\"author\" content=\"Prasad Khartadkar\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prasad Khartadkar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/\",\"name\":\"How to Redirect www or Non-www URLs with .htaccess via cPanel?\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2021\/10\/cp_redirect_www-non_www_htaccess.jpg\",\"datePublished\":\"2021-10-28T10:08:04+00:00\",\"dateModified\":\"2025-05-30T11:53:43+00:00\",\"author\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/c9138a9488172a8d0aa2d4f40878d83e\"},\"description\":\"This guide describes the process to redirect www to non-www URLs and vice-versa for your domain using the .htaccess file from cPanel.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/#primaryimage\",\"url\":\"\",\"contentUrl\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Redirect www or Non-www URLs with .htaccess via cPanel?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\",\"name\":\"Web Hosting FAQs by MilesWeb\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/c9138a9488172a8d0aa2d4f40878d83e\",\"name\":\"Prasad Khartadkar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fafb102a39aa8f8d38a11f3e2dcfa746?s=96&d=blank&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fafb102a39aa8f8d38a11f3e2dcfa746?s=96&d=blank&r=g\",\"caption\":\"Prasad Khartadkar\"},\"description\":\"Prasad is a business grad specialized in Marketing. He has garnered experience as a technical content writer and a digital marketer that he brings out in his work. He likes reading classics and travel in his free time.\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/prasad-khartadkar\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Redirect www or Non-www URLs with .htaccess via cPanel?","description":"This guide describes the process to redirect www to non-www URLs and vice-versa for your domain using the .htaccess file from cPanel.","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.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/","og_locale":"en_GB","og_type":"article","og_title":"How to Redirect www or Non-www URLs with .htaccess via cPanel?","og_description":"This guide describes the process to redirect www to non-www URLs and vice-versa for your domain using the .htaccess file from cPanel.","og_url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/","og_site_name":"Web Hosting FAQs by MilesWeb","article_published_time":"2021-10-28T10:08:04+00:00","article_modified_time":"2025-05-30T11:53:43+00:00","author":"Prasad Khartadkar","twitter_misc":{"Written by":"Prasad Khartadkar","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/","name":"How to Redirect www or Non-www URLs with .htaccess via cPanel?","isPartOf":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/#primaryimage"},"image":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/#primaryimage"},"thumbnailUrl":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2021\/10\/cp_redirect_www-non_www_htaccess.jpg","datePublished":"2021-10-28T10:08:04+00:00","dateModified":"2025-05-30T11:53:43+00:00","author":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/c9138a9488172a8d0aa2d4f40878d83e"},"description":"This guide describes the process to redirect www to non-www URLs and vice-versa for your domain using the .htaccess file from cPanel.","breadcrumb":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-redirect-www-or-non-www-url-with-htaccess-via-cpanel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/"},{"@type":"ListItem","position":2,"name":"How to Redirect www or Non-www URLs with .htaccess via cPanel?"}]},{"@type":"WebSite","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/","name":"Web Hosting FAQs by MilesWeb","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/c9138a9488172a8d0aa2d4f40878d83e","name":"Prasad Khartadkar","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/fafb102a39aa8f8d38a11f3e2dcfa746?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fafb102a39aa8f8d38a11f3e2dcfa746?s=96&d=blank&r=g","caption":"Prasad Khartadkar"},"description":"Prasad is a business grad specialized in Marketing. He has garnered experience as a technical content writer and a digital marketer that he brings out in his work. He likes reading classics and travel in his free time.","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/prasad-khartadkar\/"}]}},"views":268,"_links":{"self":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/12160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/comments?post=12160"}],"version-history":[{"count":9,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/12160\/revisions"}],"predecessor-version":[{"id":15403,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/12160\/revisions\/15403"}],"wp:attachment":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/media?parent=12160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/categories?post=12160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/tags?post=12160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}