06 Sep

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} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

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

  1. Pingback: Przekierowanie 301 - wdro?enie | SeoSem'istry - laboratorium promocji internetowej.

  2. 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 ^^

  3. Hello Sir,

    I have a dynamic site, the url structure is abc.xyz.com/State/sitemap/deep-link-page.html

    So I want to drop the “sitemap” from the Url and the url structure should be
    abc.xyz.com/State/deep-link-page.html

    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 *