{"id":16977,"date":"2024-05-21T17:53:51","date_gmt":"2024-05-21T17:53:51","guid":{"rendered":"https:\/\/hostvento.com\/kb\/web-hosting\/how-to-redirect-www-or-non-www-urls-with-htaccess-via-directadmin\/"},"modified":"2024-06-16T18:06:46","modified_gmt":"2024-06-16T18:06:46","slug":"how-to-redirect-www-or-non-www-urls-with-htaccess-via-directadmin","status":"publish","type":"docs","link":"https:\/\/www.hostvento.com\/kb\/docs\/hosting-faqs\/how-to-redirect-www-or-non-www-urls-with-htaccess-via-directadmin\/","title":{"rendered":"How to Redirect www or non-www URLs with .htaccess via DirectAdmin?"},"content":{"rendered":"\n<p>For your domain, you have the option to redirect customers from the www URL to the non-www URL and vice versa. If you are a DirectAdmin user, you may reroute traffic from www to non-www URLs or the other way around by making changes to the.htaccess file.<\/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 DirectAdmin.<\/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. Copy and paste 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<\/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\/da_redirect_www-non_www_htaccess.jpg\" alt=\"\" class=\"wp-image-13659\"\/><\/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 DirectAdmin 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<\/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\/da_redirect_non_www-www_htaccess.jpg\" alt=\"\" class=\"wp-image-13660\"\/><\/figure>\n<\/div>\n\n\n<p><strong>Note<\/strong>: If the .htaccess file already contains a code for redirection directive, you will have to&nbsp;substitute it with the new one to modify the redirection settings.<\/p>\n\n\n\n<p>Here\u2019s how we&nbsp;configured the .htaccess file of a sample domain in DirectAdmin to redirect users from non-www to www URLs:<\/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\/da_redirect_non_www-www_htaccess_example.jpg\" alt=\"\" class=\"wp-image-13661\"\/><\/figure>\n<\/div>\n\n\n<p><strong>Redirects to:<\/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\/da_redirect_non_www-www_htaccess_example2.jpg\" alt=\"\" class=\"wp-image-13662\"\/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For your domain, you have the option to redirect customers from the www URL to the non-www URL and vice versa. If you are a DirectAdmin user, you may reroute traffic from www to non-www URLs or the other way around by making changes to the.htaccess file. To Redirect www to Non-www URLs with .htaccess [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":23377,"menu_order":564,"comment_status":"closed","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-16977","docs","type-docs","status-publish","hentry","no-post-thumbnail"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs\/16977","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=16977"}],"version-history":[{"count":1,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs\/16977\/revisions"}],"predecessor-version":[{"id":16984,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/docs\/16977\/revisions\/16984"}],"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=16977"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.hostvento.com\/kb\/wp-json\/wp\/v2\/doc_tag?post=16977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}