{"id":7,"date":"2018-04-08T06:56:27","date_gmt":"2018-04-08T06:56:27","guid":{"rendered":"https:\/\/www.onlinenote.in\/htaccess\/?p=7"},"modified":"2019-05-02T11:07:30","modified_gmt":"2019-05-02T05:37:30","slug":"redirect-non-www-to-www-in-htaccess","status":"publish","type":"post","link":"https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/","title":{"rendered":"Redirect non-www to www in .htaccess"},"content":{"rendered":"<p>Below snippet shows how to redirect a site from non-www to www<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">RewriteCond %{HTTP_HOST} ^onlinenote.in$ [NC]\r\nRewriteRule (.*) http:\/\/www.onlinenote.in\/$1 [R=301,L]<\/pre>\n<p>or<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">RewriteEngine On\r\nRewriteCond %{HTTP_HOST} !^www\\. [NC]\r\nRewriteRule ^(.*)$ http:\/\/www.%{HTTP_HOST}\/$1 [R=301,L]<\/pre>\n<p>or<\/p>\n<p>Here&#8217;s the correct solution which supports https and http:<\/p>\n<pre class=\"toolbar:1 lang:default decode:true \">RewriteEngine on\r\nRewriteCond %{HTTP_HOST} !^www\\.\r\nRewriteCond %{HTTPS}s on(s)|offs()\r\nRewriteRule ^ http%1:\/\/www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below snippet shows how to redirect a site from non-www to www RewriteCond %{HTTP_HOST} ^onlinenote.in$ [NC] RewriteRule (.*) http:\/\/www.onlinenote.in\/$1 [R=301,L] or RewriteEngine On RewriteCond %{HTTP_HOST} !^www\\. [NC] RewriteRule ^(.*)$ http:\/\/www.%{HTTP_HOST}\/$1 [R=301,L] or Here&#8217;s the correct solution which supports https and http: RewriteEngine on RewriteCond %{HTTP_HOST} !^www\\. RewriteCond %{HTTPS}s on(s)|offs() RewriteRule ^ http%1:\/\/www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R] &nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Redirect non-www to www in .htaccess - htaccess<\/title>\n<meta name=\"description\" content=\"Using htaccess file to redirect a site from www to non-www and from HTTP to HTTPS also to redirect the www to the non-www version.\" \/>\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.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Redirect non-www to www in .htaccess - htaccess\" \/>\n<meta property=\"og:description\" content=\"Using htaccess file to redirect a site from www to non-www and from HTTP to HTTPS also to redirect the www to the non-www version.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/\" \/>\n<meta property=\"og:site_name\" content=\"htaccess\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-08T06:56:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-05-02T05:37:30+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/\",\"url\":\"https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/\",\"name\":\"Redirect non-www to www in .htaccess - htaccess\",\"isPartOf\":{\"@id\":\"https:\/\/www.onlinenote.in\/htaccess\/#website\"},\"datePublished\":\"2018-04-08T06:56:27+00:00\",\"dateModified\":\"2019-05-02T05:37:30+00:00\",\"author\":{\"@id\":\"\"},\"description\":\"Using htaccess file to redirect a site from www to non-www and from HTTP to HTTPS also to redirect the www to the non-www version.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.onlinenote.in\/htaccess\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Redirect non-www to www in .htaccess\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.onlinenote.in\/htaccess\/#website\",\"url\":\"https:\/\/www.onlinenote.in\/htaccess\/\",\"name\":\"htaccess\",\"description\":\"Code Snippets\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.onlinenote.in\/htaccess\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Redirect non-www to www in .htaccess - htaccess","description":"Using htaccess file to redirect a site from www to non-www and from HTTP to HTTPS also to redirect the www to the non-www version.","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.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/","og_locale":"en_US","og_type":"article","og_title":"Redirect non-www to www in .htaccess - htaccess","og_description":"Using htaccess file to redirect a site from www to non-www and from HTTP to HTTPS also to redirect the www to the non-www version.","og_url":"https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/","og_site_name":"htaccess","article_published_time":"2018-04-08T06:56:27+00:00","article_modified_time":"2019-05-02T05:37:30+00:00","twitter_card":"summary_large_image","twitter_misc":{"Written by":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/","url":"https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/","name":"Redirect non-www to www in .htaccess - htaccess","isPartOf":{"@id":"https:\/\/www.onlinenote.in\/htaccess\/#website"},"datePublished":"2018-04-08T06:56:27+00:00","dateModified":"2019-05-02T05:37:30+00:00","author":{"@id":""},"description":"Using htaccess file to redirect a site from www to non-www and from HTTP to HTTPS also to redirect the www to the non-www version.","breadcrumb":{"@id":"https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.onlinenote.in\/htaccess\/redirect-non-www-to-www-in-htaccess\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.onlinenote.in\/htaccess\/"},{"@type":"ListItem","position":2,"name":"Redirect non-www to www in .htaccess"}]},{"@type":"WebSite","@id":"https:\/\/www.onlinenote.in\/htaccess\/#website","url":"https:\/\/www.onlinenote.in\/htaccess\/","name":"htaccess","description":"Code Snippets","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.onlinenote.in\/htaccess\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":""}]}},"_links":{"self":[{"href":"https:\/\/www.onlinenote.in\/htaccess\/wp-json\/wp\/v2\/posts\/7"}],"collection":[{"href":"https:\/\/www.onlinenote.in\/htaccess\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.onlinenote.in\/htaccess\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.onlinenote.in\/htaccess\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.onlinenote.in\/htaccess\/wp-json\/wp\/v2\/comments?post=7"}],"version-history":[{"count":2,"href":"https:\/\/www.onlinenote.in\/htaccess\/wp-json\/wp\/v2\/posts\/7\/revisions"}],"predecessor-version":[{"id":41,"href":"https:\/\/www.onlinenote.in\/htaccess\/wp-json\/wp\/v2\/posts\/7\/revisions\/41"}],"wp:attachment":[{"href":"https:\/\/www.onlinenote.in\/htaccess\/wp-json\/wp\/v2\/media?parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.onlinenote.in\/htaccess\/wp-json\/wp\/v2\/categories?post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.onlinenote.in\/htaccess\/wp-json\/wp\/v2\/tags?post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}