Remove www From URL using .htaccess in Apache

This htaccess code will remove the ‘www’ part from the url. It uses the mod_rewrite module of apache to re-write the url – so make sure that’s installed.

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^[NC]
RewriteRule ^(.*)$1 [R=301,L]
Author: Binny V A
A philosopher programmer who specializes in backend development and stoicism.

5 thoughts on “Remove www From URL using .htaccess in Apache

  1. Thanks you for this helpful code… WordPress was killing me, sometimes it worked, sometimes not, until I found out, that it depended on the written url: with www bad (header already send error), without fine, so your code was exactly what fixed my prob ^^

  2. Hello Sir,

    I have a dynamic site, the url structure is

    So I want to drop the “sitemap” from the Url and the url structure should be

    Can anyone suggest me the htaccess code so that it would be helpful for me.

    Thanks in Advance

Leave a Reply

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