{"id":993,"date":"2016-08-04T11:19:45","date_gmt":"2016-08-04T05:49:45","guid":{"rendered":"https:\/\/www.nettigritty.com\/kb\/?p=993"},"modified":"2022-06-05T18:19:52","modified_gmt":"2022-06-05T12:49:52","slug":"redirect-all-requests-to-www-website-from-non-www","status":"publish","type":"post","link":"https:\/\/www.nettigritty.com\/kb\/website\/redirect-all-requests-to-www-website-from-non-www\/","title":{"rendered":"Redirect all requests to www.website (or non-www)"},"content":{"rendered":"<p>Redirecting your website from non-www to www URLs can be as simple as adding suitable code in your .htaccess file.<\/p>\n<p>For non-WordPress websites, you can use the code below replacing domainname.com with your own domain name.<\/p>\n<p><code># ensure www.<br \/>\nRewriteEngine on<br \/>\nRewriteCond %{HTTP_HOST} !^www\\. [NC]<br \/>\nRewriteRule ^ https:\/\/www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]]<\/code><\/p>\n<p>Alternate code:<\/p>\n<p><code>RewriteEngine on<br \/>\nRewriteCond %{HTTP_HOST} ^domainname.com$<br \/>\nRewriteRule ^(.*)$ http:\/\/www.domainname.com\/$1 [R=301,L]<\/code><\/p>\n<p class=\"lang-apacheconf s-code-block\"><code class=\"hljs language-perl\"><\/code><\/p>\n<p>For WordPress websites, this should be done by setting the URLs in your WordPress General Settings. Using the code above for a WordPress website can put it in a loop.<\/p>\n<p>You can also force non-www URLs in a similar way by changing the code as follows. Again, this should be placed in your .htaccess file located in your public_html folder.<\/p>\n<p><code>RewriteEngine on<br \/>\nRewriteCond %{HTTP_HOST} ^www\\.domainname\\.com [NC]<br \/>\nRewriteRule ^(.*)$ http:\/\/domainname.com\/$1 [L,R=301]<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redirecting your website from non-www to www URLs can be as simple as adding suitable code in your .htaccess file. For non-WordPress websites, you can use the code below replacing domainname.com with your own domain name. # ensure www. RewriteEngine on RewriteCond %{HTTP_HOST} !^www\\. [NC] RewriteRule ^ https:\/\/www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]] Alternate code: RewriteEngine on RewriteCond %{HTTP_HOST} [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-993","post","type-post","status-publish","format-standard","hentry","category-website"],"_links":{"self":[{"href":"https:\/\/www.nettigritty.com\/kb\/wp-json\/wp\/v2\/posts\/993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nettigritty.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nettigritty.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nettigritty.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nettigritty.com\/kb\/wp-json\/wp\/v2\/comments?post=993"}],"version-history":[{"count":7,"href":"https:\/\/www.nettigritty.com\/kb\/wp-json\/wp\/v2\/posts\/993\/revisions"}],"predecessor-version":[{"id":2916,"href":"https:\/\/www.nettigritty.com\/kb\/wp-json\/wp\/v2\/posts\/993\/revisions\/2916"}],"wp:attachment":[{"href":"https:\/\/www.nettigritty.com\/kb\/wp-json\/wp\/v2\/media?parent=993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nettigritty.com\/kb\/wp-json\/wp\/v2\/categories?post=993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nettigritty.com\/kb\/wp-json\/wp\/v2\/tags?post=993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}