Knowledgebase » Web Servers » How to redirect all traffic to ‘www’ to your website domain without the prefix

How to redirect all traffic to ‘www’ to your website domain without the prefix

This article explains how to redirect all traffic directed at “www” to your website domain without the “www”.

Create a .htaccess file in the root of your website folder. Add the following contents into it:

<span class="typ" style="font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; color: #2b91af;">RewriteCond</span> <span class="pun" style="font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;">%{</span><span class="pln" style="font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;">HTTP_HOST</span><span class="pun" style="font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;">}</span> <span class="pun" style="font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;">^</span><span class="pln" style="font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;">www\.</span><span class="pun" style="font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;">(.+)</span><span class="pln" style="font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;">$ </span><span class="pun" style="font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;">[</span><span class="pln" style="font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;">NC</span><span class="pun" style="font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;">]
RewiteRule <span class="pun" style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; white-space: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;">^</span><span class="pln" style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; white-space: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;"> https</span><span class="pun" style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; white-space: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: #303336;">:</span><span class="com" style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; white-space: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: #858c93;">//%1%{REQUEST_URI} [L,R=301]</span></span>

Share this article

Share on facebook
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top