{"id":16987,"date":"2024-05-21T17:56:10","date_gmt":"2024-05-21T17:56:10","guid":{"rendered":"https:\/\/hostvento.com\/kb\/web-hosting\/how-to-redirect-www-or-non-www-urls-with-htaccess-via-cpanel\/"},"modified":"2024-06-16T18:06:41","modified_gmt":"2024-06-16T18:06:41","slug":"how-to-redirect-www-or-non-www-urls-with-htaccess-via-cpanel","status":"publish","type":"docs","link":"https:\/\/www.hostvento.com\/kb\/docs\/hosting-faqs\/how-to-redirect-www-or-non-www-urls-with-htaccess-via-cpanel\/","title":{"rendered":"How to Redirect www or Non-www URLs with .htaccess via cPanel?"},"content":{"rendered":"\n<p>For your domain, you may make users switch from www to non-www URLs and vice versa. You may put a directive in the.htaccess file as a cPanel user to redirect from www to non-www URLs or the other way around.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">To Redirect www to Non-www URLs with .htaccess<\/h2>\n\n\n\n<p>1. Log in to your cPanel account.<\/p>\n\n\n\n<p>2. Create\/edit&nbsp;<strong>.htaccess<\/strong>&nbsp;file in the document root of your domain via&nbsp;<em>File Manager<\/em>.<\/p>\n\n\n\n<p>3. Add this code at the end of the file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># 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\n\n\n<p>4. Click on&nbsp;<strong>Save Changes<\/strong>&nbsp;and&nbsp;<strong>Close<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.hostvento.com\/kb\/hosting-faqs\/wp-content\/uploads\/2021\/10\/cp_redirect_www-non_www_htaccess.jpg\" alt=\"\" class=\"wp-image-13647\"\/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">To Redirect Non-www to www URLs with .htaccess<\/h2>\n\n\n\n<p>1. Log in to your cPanel account.<\/p>\n\n\n\n<p>2. Create\/edit&nbsp;<strong>.htaccess<\/strong>&nbsp;file in the document root of your domain via&nbsp;<em>File Manager<\/em>.<\/p>\n\n\n\n<p>3. Add this code at the end of the file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># 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\n\n\n<p>4. Click on&nbsp;<strong>Save Changes<\/strong>&nbsp;and&nbsp;<strong>Close<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.hostvento.com\/kb\/hosting-faqs\/wp-content\/uploads\/2021\/10\/cp_redirect_non_www-www_htaccess.jpg\" alt=\"\" class=\"wp-image-13646\"\/><\/figure>\n<\/div>\n\n\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\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For your domain, you may make users switch from www to non-www URLs and vice versa. You may put a directive in the.htaccess file as a cPanel user to redirect from www to non-www URLs or the other way around. To Redirect www to Non-www URLs with .htaccess 1. Log in to your cPanel account. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":23377,"menu_order":566,"comment_status":"closed","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-16987","docs","type-docs","status-publish","hentry","no-post-thumbnail"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs\/16987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/comments?post=16987"}],"version-history":[{"count":1,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs\/16987\/revisions"}],"predecessor-version":[{"id":16991,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs\/16987\/revisions\/16991"}],"up":[{"embeddable":true,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs\/23377"}],"wp:attachment":[{"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/media?parent=16987"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/doc_tag?post=16987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}