We Recommend

Pro Apache Pro Apache
In addition to installation, maintenance, and deployment, the book demonstrates how to configure Apache to use Perl, PHP, and Python as server-side scripting languages. And unlike other books on Apache, Pro Apache provides comprehensive information on both major revisions - 1.3 and 2.0 - of the software.


Posted By

torkil on 01/16/08


Tagged

url modrewrite htaccess apache www seo domains


Versions (?)


Who likes this?

5 people have marked this snippet as a favorite

adix
eszpee
cyrilbatillat
snucko
torkil


Force removal of WWW in url


Published in: Apache 


URL: http://www.torkiljohnsen.com/2008/01/16/some-easy-use-of-mod_rewrite/

Using mod_rewrite in Apache to rewrite urls and force removal of www in urls. Good for letting search engine spiders in the right door...

Insert the code in your .htaccess-file in your website's root folder.


  1. # force removal of www IN URL
  2. RewriteEngine On
  3. RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
  4. RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
  5. # END force removal of www IN URL# force www IN URL

Report this snippet 

You need to login to post a comment.