General

How to redirect www to non-www with the .htaccess

February 4, 2015

redirect a url

I’ve seen this done many ways, but my go to script is simple and doesn’t require any customizations for each domain.

Here’s my quick and simple way to force www to non-www.

Add this to your .htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>

 

Anthony Montalbano

If it's worth doing, it's worth doing right.

Published on: February 4, 2015

Last modified on: December 8, 2021