{"id":561,"date":"2021-10-15T10:06:55","date_gmt":"2021-10-15T10:06:55","guid":{"rendered":"http:\/\/blog.hostinger.io\/hostinger-tutorials\/uncategorized\/cpanelhow-to-redirect-non-www-urls-to-www\/"},"modified":"2026-03-09T19:19:03","modified_gmt":"2026-03-09T19:19:03","slug":"redirect-non-www-urls-www","status":"publish","type":"post","link":"\/ng\/tutorials\/redirect-non-www-urls-www","title":{"rendered":"How to redirect non-www to www URLs"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>As a website owner, you might have wondered whether using a www or non-www website domain is simply a matter of user preference.<\/p><p>Even though a non-www domain may be simpler and easier for your audience to remember, it has some disadvantages compared to a www domain.<\/p><p>A www domain helps avoid both the possibility of split page ranking or split inbound links and any duplicate content when search engines index the site. Thus, it improves your site&rsquo;s search engine optimization (SEO).<\/p><p>If you use a non-www URL, redirecting it to www may seem intimidating, but it&rsquo;s not a complicated process. Keep reading, as this article will show you three different methods to redirect non-www to www URLs.<\/p><figure class=\"wp-block-image size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/How-to-Speed-Up-Your-Website-EN.pdf\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/public\" alt=\"\" class=\"wp-image-69260\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/eBook-Speed-Up-your-website.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure><p>\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-why-redirect-non-www-urls-to-www\">Why Redirect Non-www URLs to www?<\/h2><p>Sticking with a non-www domain has some drawbacks, including the lack of overload protection and control over cookies.<\/p><p>Traffic from non-www domains can&rsquo;t be redirected to another server because they don&rsquo;t have a <a href=\"https:\/\/support.hostinger.com\/en\/articles\/4738777-how-to-add-and-remove-cname-records-on-hpanel\">CNAME record<\/a>. Due to that, if your server experiences an overload, you won&rsquo;t be able to redirect traffic to a healthy server.<\/p><p>Thus, visitors may have a hard time accessing your website, negatively affecting its <a href=\"\/ng\/tutorials\/website-performance\">performance<\/a> and SEO.<\/p><p>In addition to that, search engines consider <strong>https:\/\/www.yourdomain.com<\/strong> and <strong>http:\/\/yourdomain.com<\/strong> different websites. Therefore, they are ranked separately and require distinct SEO strategies.<\/p><p>Also, with a non-www domain, you can&rsquo;t use a <a href=\"\/ng\/tutorials\/cookieless-domain-warning\">cookie-free subdomain<\/a> unless you create a separate domain to deliver static content.<\/p><p>On the other hand, a www URL allows you to restrict cookies to the root domain or a specific subdomain, reducing the number of HTTP requests and improving the performance of the website.<\/p><h2 class=\"wp-block-heading\" id=\"h-redirecting-non-www-urls-to-www\">Redirecting Non-www URLs to www<\/h2><p>There are several ways to redirect non-www URLs to www &ndash; via your hosting account&rsquo;s control panel, a <a href=\"\/ng\/tutorials\/what-is-cdn\">content delivery network<\/a> (CDN), or web server software.<\/p><p>To avoid losing your ranking power, we recommend performing a permanent 301 redirect instead of a temporary one.<\/p><p>    <p class=\"warning\">\n        <b>Warning!<\/b> Before proceeding to the tutorial, make sure you have a backup of your website files. This way, you can restore the site to a previous version if an error occurs during the process.    <\/p>\n    \n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-hpanel\">hPanel<\/h3><p>The easiest way of redirecting a non-www URL to www is to place a rule in the <strong>.htaccess <\/strong>file. You can do so via<a href=\"\/ng\/tutorials\/what-is-ftp\"> FTP<\/a>,<a href=\"\/ng\/tutorials\/ssh-tutorial-how-does-ssh-work\"> SSH<\/a>, or your hosting account&rsquo;s control panel.<\/p><p>hPanel users can easily access and edit the <strong>.htaccess<\/strong> file. Here are the steps to do it:<\/p><ol class=\"wp-block-list\">\n<li>Log in to your <strong>hPanel<\/strong>, scroll down to the <strong>Files <\/strong>section, and open the <strong>File Manager<\/strong>.<\/li>\n<\/ol><figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-sidebar-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"448\" height=\"522\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-sidebar-1.png\/public\" alt=\"The File Manager option on hPanel\" class=\"wp-image-80655\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-sidebar-1.png\/w=448,fit=scale-down 448w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-sidebar-1.png\/w=257,fit=scale-down 257w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-sidebar-1.png\/w=129,fit=scale-down 129w\" sizes=\"auto, (max-width: 448px) 100vw, 448px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"2\">\n<li>Navigate to the <strong>public_html<\/strong> directory, right-click the <strong>.htaccess <\/strong>file, and select <strong>Edit<\/strong>.<strong> <\/strong>If you can&rsquo;t find it, refer to our article to learn <a href=\"\/ng\/tutorials\/locate-and-create-htaccess\">how to create the .htaccess file<\/a> for your WordPress site.<\/li>\n<\/ol><figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-public_html-edit.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"203\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-public_html-edit.png\/public\" alt=\"The public_html directory on hPanel with the Edit option highlighted\" class=\"wp-image-80753\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-public_html-edit.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-public_html-edit.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-public_html-edit.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-public_html-edit.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"3\">\n<li>Find the line <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">RewriteEngine On<\/code><strong> <\/strong>and insert the following code after it:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]<\/code><br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">RewriteRule ^(.*)$ http:\/\/www.yourdomain.com\/$1 [L,R=301]<\/code><\/li>\n<\/ol><figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-public_html-htaccess.png\"><img loading=\"lazy\" decoding=\"async\" width=\"463\" height=\"85\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-public_html-htaccess.png\/public\" alt=\"RewriteEngine On code line highlighted along with the inserted code.\" class=\"wp-image-80761\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-public_html-htaccess.png\/w=463,fit=scale-down 463w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-public_html-htaccess.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/hpanel-files-filemanager-public_html-htaccess.png\/w=150,fit=scale-down 150w\" sizes=\"auto, (max-width: 463px) 100vw, 463px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"4\">\n<li>Don&rsquo;t forget to replace <strong>yourdomain.com<\/strong> with your actual domain name<strong>.<\/strong> Once you&rsquo;re done, <strong>save <\/strong>the changes.<\/li>\n<\/ol><p>This <strong>.htaccess<\/strong> rule will now redirect all visitors from the non-www to the www version of your website.<\/p><h3 class=\"wp-block-heading\" id=\"h-cpanel\">cPanel<\/h3><p><a href=\"\/ng\/tutorials\/what-is-cpanel\">cPanel<\/a> users can redirect non-www URLs to www via the <strong>Redirect<\/strong> settings or editing the <strong>.htaccess<\/strong> file. If you are a beginner, we recommend following the first method:<\/p><ol class=\"wp-block-list\">\n<li>Access your <strong>cPanel<\/strong>, then navigate to <strong>Domains <\/strong>-&gt;<strong> Redirects<\/strong>.<\/li>\n<\/ol><figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-domains-redirects.png\"><img loading=\"lazy\" decoding=\"async\" width=\"777\" height=\"192\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-domains-redirects.png\/public\" alt=\"The Redirects menu on cPanel\" class=\"wp-image-80771\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-domains-redirects.png\/w=777,fit=scale-down 777w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-domains-redirects.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-domains-redirects.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-domains-redirects.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 777px) 100vw, 777px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"2\">\n<li>Under <strong>Type<\/strong>, select the <strong>Permanent (301)<\/strong> option.<\/li>\n\n\n\n<li>On <strong>https?:\/\/<\/strong>, enter the domain you want to redirect. Leave the path section (\/) empty.<\/li>\n\n\n\n<li>In the <strong>Redirects to<\/strong> field, type in your website&rsquo;s www URL.<\/li>\n\n\n\n<li>Select <strong>Do Not Redirect www<\/strong>, and uncheck <strong>Wild Card Redirect<\/strong>.<\/li>\n<\/ol><ol class=\"wp-block-list\" start=\"6\">\n<li>Press the <strong>Add <\/strong>button.<\/li>\n<\/ol><figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-domains-redirects-addredirect.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"427\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-domains-redirects-addredirect.png\/public\" alt=\"The Add Redirect section on cPanel's Redirects menu\" class=\"wp-image-80777\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-domains-redirects-addredirect.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-domains-redirects-addredirect.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-domains-redirects-addredirect.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-domains-redirects-addredirect.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>If the above method doesn&rsquo;t work, you can set the redirect manually by editing the <strong>.htaccess<\/strong> file:<\/p><ol class=\"wp-block-list\">\n<li>From your cPanel<strong> <\/strong>dashboard, go to <strong>Files<\/strong> -&gt;<strong> File Manager<\/strong>.<\/li>\n<\/ol><figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-files-filemanager.png\"><img loading=\"lazy\" decoding=\"async\" width=\"765\" height=\"305\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-files-filemanager.png\/public\" alt=\"The File Manager menu on cPanel\" class=\"wp-image-80780\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-files-filemanager.png\/w=765,fit=scale-down 765w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-files-filemanager.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/cpanel-files-filemanager.png\/w=150,fit=scale-down 150w\" sizes=\"auto, (max-width: 765px) 100vw, 765px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"2\">\n<li>Look for the <strong>public_html<\/strong> folder and double-click it.<\/li>\n<\/ol><figure class=\"wp-block-image size-large\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/10\/public-html-folder.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1366\" height=\"653\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/public-html-folder.png\/public\" alt=\"public_html folder on cPanel\" class=\"wp-image-37860\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/public-html-folder.png\/w=1366,fit=scale-down 1366w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/public-html-folder.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/public-html-folder.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/public-html-folder.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/public-html-folder.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"3\">\n<li>Right-click the <strong>.htaccess<\/strong> file and select <strong>Edit<\/strong>.<\/li>\n<\/ol><figure class=\"wp-block-image size-large\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/10\/edit-htaccess.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"490\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/edit-htaccess.png\/public\" alt=\"Editing the .htaccess file on cPanel\" class=\"wp-image-37861\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/edit-htaccess.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/edit-htaccess.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/edit-htaccess.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/edit-htaccess.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"4\">\n<li>Under <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">RewriteEngine On<\/code>, insert the following lines of code:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]<\/code><br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">RewriteRule ^(.*)$ http:\/\/www.yourdomain.com\/$1 [L,R=301]<\/code><\/li>\n<\/ol><figure class=\"wp-block-image size-large\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/10\/cpanel-code-snippet.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1366\" height=\"654\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/cpanel-code-snippet.png\/public\" alt=\"Redirect the code snippet on cPanel\" class=\"wp-image-37862\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/cpanel-code-snippet.png\/w=1366,fit=scale-down 1366w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/cpanel-code-snippet.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/cpanel-code-snippet.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/cpanel-code-snippet.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/cpanel-code-snippet.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/figure><p><div><p class=\"important\"><strong>Important!<\/strong> Don&rsquo;t forget to replace yourdomain.com with your actual domain name.<\/p><\/div>\n\n\n\n<\/p><ol class=\"wp-block-list\" start=\"5\">\n<li>Save Changes<\/li>\n<\/ol><h3 class=\"wp-block-heading\" id=\"h-cloudflare\">Cloudflare<\/h3><p>If you&rsquo;re planning on setting up a CDN like Cloudflare to improve the speed and performance of the site, you will also be able to use it to redirect the non-www to the www domain.<\/p><p><div class=\"editor\">\n                    <h4 class=\"title\">Expert Tip<\/h4>\n                    <p>You may want to check the following tutorials before proceeding:<br>\n<a href=\"\/ng\/tutorials\/how-to-setup-cloudflare-for-wordpress\">Cloudflare setup process for WordPress sites<\/a><br>\n<a href=\"\/ng\/tutorials\/improving-website-performance-using-a-cdn\">Cloudflare setup tutorial for general websites<\/a><\/p>\n                    <div class=\"d-flex mt-40\">\n                        <div class=\"author-photo\">\n                            <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/secure.gravatar.com\/avatar\/96cd154ae688d7a15a7d0d0e65a85234281f31e2b23b34b93d5cd081271defc2?s=65&d=mm&r=g\" width=\"65\" height=\"65\" class=\"border-radius-50\" alt=\"Editor\" \/>\n                        <\/div>\n                        <div class=\"mt-auto mb-auto\">\n                            <p class=\"author-name\">Darius G.<\/p>\n                            <p class=\"author-position\">Chief Customer Officer<\/p>\n                        <\/div>\n                    <\/div>\n                <\/div>\n\n\n\n<\/p><p>Once you&rsquo;ve created an account, log in, and set up a <a href=\"\/ng\/tutorials\/cloudflare-page-rules\">page rule on your Cloudflare<\/a>:<\/p><ol class=\"wp-block-list\">\n<li>On your <strong>Cloudflare dashboard<\/strong>, click on the <strong>Rules<\/strong> tab.<\/li>\n<\/ol><figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/03\/The-Rules-menu-on-the-Cloudflare-dashboard.png\"><img loading=\"lazy\" decoding=\"async\" width=\"249\" height=\"567\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/The-Rules-menu-on-the-Cloudflare-dashboard.png\/public\" alt=\"The Rules menu on the Cloudflare dashboard\" class=\"wp-image-80794\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/The-Rules-menu-on-the-Cloudflare-dashboard.png\/w=249,fit=scale-down 249w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/The-Rules-menu-on-the-Cloudflare-dashboard.png\/w=132,fit=scale-down 132w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/03\/The-Rules-menu-on-the-Cloudflare-dashboard.png\/w=66,fit=scale-down 66w\" sizes=\"auto, (max-width: 249px) 100vw, 249px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"2\">\n<li>Press the <strong>Create Page Rule<\/strong> button.<\/li>\n\n\n\n<li>Type in your current website URL without the www, then set the page rule as <strong>Forwarding URL<\/strong>.<\/li>\n\n\n\n<li>Select <strong>301 &ndash; Permanent Redirect<\/strong> as the status code.<\/li>\n<\/ol><figure class=\"wp-block-image size-full\"><a href=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/10\/page-rule.png\"><img loading=\"lazy\" decoding=\"async\" width=\"935\" height=\"483\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/page-rule.png\/public\" alt=\"Creating a page rule on Cloudflare\" class=\"wp-image-37864\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/page-rule.png\/w=935,fit=scale-down 935w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/page-rule.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/page-rule.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2021\/10\/page-rule.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 935px) 100vw, 935px\" \/><\/a><\/figure><ol class=\"wp-block-list\" start=\"5\">\n<li>Type in your website&rsquo;s URL with the www, then click <strong>Save and Deploy<\/strong>.<\/li>\n<\/ol><p>Wait for the redirect to go live.<\/p><h3 class=\"wp-block-heading\">NGINX<\/h3><p>If you use <a href=\"\/ng\/vps-hosting\">virtual server hosting<\/a> and <a href=\"\/ng\/tutorials\/what-is-nginx\">NGINX<\/a>, follow the tutorial below to redirect non-www URLs to www:<\/p><ol class=\"wp-block-list\">\n<li>Log in to your VPS account using an SSH like <a href=\"\/ng\/tutorials\/how-to-use-putty-ssh\">PuTTY<\/a>.<\/li>\n\n\n\n<li>Navigate to the directory <strong>\/etc\/nginx\/<\/strong>.<\/li>\n\n\n\n<li>Type in the command below to view the directory content:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">[server]$ sudo ls - la<\/code><\/li>\n\n\n\n<li>Enter your NGINX password.<\/li>\n\n\n\n<li>Type in the following command to edit the nginx.conf file:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">[server]$ sudo nano nginx.conf<\/code><\/li>\n\n\n\n<li>Add the following lines of code, replacing yourdomain.com with your actual domain name:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">server {<\/code><br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">server_name yourdomain.com;<\/code><br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">return 301 $scheme:\/\/www.yourdomain.com$request_uri;<\/code><br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">}<\/code><\/li>\n\n\n\n<li>Enter the following command to restart the NGINX web server:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">sudo systemctl restart Nginx<\/code><\/li>\n<\/ol><p>In addition to redirecting non-www to www URLs, you can also <a href=\"\/ng\/tutorials\/nginx-redirect\/\">run other redirects through NGINX<\/a>, such as HTTP to HTTPS and other page redirects.<\/p><p><div class=\"protip\">\n                    <h4 class=\"title\">Pro Tip<\/h4>\n                    <p>Hostinger users can manage their VPS from the new browser-based terminal, eliminating the need for additional software.<\/p>\n                <\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\">Apache<\/h3><p>If you&rsquo;re a VPS and <a href=\"\/ng\/tutorials\/what-is-apache\">Apache<\/a> user, you&rsquo;ll also need to edit the <strong>.htaccess<\/strong> file. Just like the previous tutorial, it can be done via an SSH terminal.<\/p><p><div><p class=\"important\"><strong>Important!<\/strong> Before continuing with the steps below, make sure you have root access with <a href=\"\/ng\/tutorials\/sudo-and-the-sudoers-file\/\">sudo privileges<\/a> and a text editor like <a href=\"https:\/\/www.nano-editor.org\/\">Nano<\/a>.<\/p><\/div>\n\n\n\n<\/p><p>By default, Apache doesn&rsquo;t allow the use of <strong>.htaccess<\/strong> file, so the steps will be a little different:<\/p><ol class=\"wp-block-list\">\n<li><strong>Enable mod_rewrite<\/strong> by running the following command:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">$ sudo a2enmod rewrite<\/code><br>Then, restart the Apache web server:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">$ sudo systemctl restart apache2<\/code><\/li>\n\n\n\n<li><strong>Enable .htaccess<\/strong> with the command:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">$ sudo vi \/etc\/apache2\/sites-available\/000-default.conf<\/code><br>Add the following code before the <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">&lt;VirtualHost&gt;<\/code> line:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">&lt;Directory \/var\/www\/html&gt;<\/code><br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">Options Indexes FollowSymLinks MultiViews<\/code><br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">AllowOverride All<\/code><br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">Require all granted<\/code><br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">&lt;\/Directory&gt;<\/code><br>Then, restart Apache.<\/li>\n\n\n\n<li>To create the<strong> .htaccess<\/strong> file, enter the command:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">$ sudo vi \/var\/www\/html\/.htaccess<\/code><\/li>\n\n\n\n<li>Add the following lines to the file:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">RewriteEngine on<\/code><br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]<\/code><br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">RewriteRule ^(.*)$ http:\/\/www.yourdomain.com\/$1 [L,R=301]<\/code><\/li>\n\n\n\n<li>Restart the Apache server.<\/li>\n<\/ol><p>All site visitors using the non-www URL should now be redirected to the www version.<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>People tend to leave the www out when typing a website&rsquo;s address. It might not cause significant issues since visitors will reach the same page, but it&rsquo;s best to redirect site visitors to its www version.<\/p><p>This is because your site&rsquo;s performance and SEO might be affected if you keep using non-www domains.<\/p><p>Though it may sound complicated, the redirect process will only take a minute or two. In this article, you&rsquo;ve learned how to redirect non-www URLs to www in several ways:<\/p><ul class=\"wp-block-list\">\n<li>Via your hosting account&rsquo;s control panel &ndash; hPanel and cPanel.<\/li>\n\n\n\n<li>Using Cloudflare.<\/li>\n\n\n\n<li>For VPS users, via NGINX and Apache.<\/li>\n<\/ul><p>Now, whenever someone accesses your site using <strong>http:\/\/yourdomain.com<\/strong>, they will be redirected to <strong>http:\/\/www.yourdomain.com<\/strong>.<\/p><p>We hope this article was helpful. Let us know in the comments below if you have any questions.<\/p><p><div class=\"protip\">\n                    <h4 class=\"title\">Suggested Reading<\/h4>\n                    <p>Check out our tutorial featuring <a href=\"\/ng\/tutorials\/website-optimization-tools\">The Best Tools For Website Optimization<\/a>, ensuring a smoother and more engaging user experience.<\/p>\n                <\/div>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a website owner, you might have wondered whether using a www or non-www website domain is simply a matter of user preference. Even though a non-www domain may be simpler and easier for your audience to remember, it has some disadvantages compared to a www domain. A www domain helps avoid both the possibility [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ng\/tutorials\/redirect-non-www-urls-www\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":24,"featured_media":144718,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Easily Redirect Non-www websites to www","rank_math_description":"Using non-www domains may affect your site\u2019s performance and SEO. In this tutorial, learn different ways to redirect non-www URLs to www.","rank_math_focus_keyword":"redirect non-www to www","footnotes":""},"categories":[22630],"tags":[],"class_list":["post-561","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technical-aspects"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/redirect-non-www-urls-www","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/redirection-non-www-vers-www","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/como-redirigir-una-url-sin-www-a-www","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-redirect-non-www-to-www","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/redirect-non-www-urls-www","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/redirect-non-www-urls-www","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/redirect-non-www-urls-www","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/redirect-non-www-urls-www","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/redirect-non-www-urls-www","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/como-redirigir-una-url-sin-www-a-www","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/como-redirigir-una-url-sin-www-a-www","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/como-redirigir-una-url-sin-www-a-www","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/redirect-non-www-urls-www","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/redirect-non-www-urls-www","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/561","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/comments?post=561"}],"version-history":[{"count":39,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/561\/revisions"}],"predecessor-version":[{"id":144717,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/561\/revisions\/144717"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media\/144718"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media?parent=561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/categories?post=561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/tags?post=561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}