nixCraft Poll

Topics

Lighttpd redirect www.domain.com requests to domain.com or vice versa

Posted by Vivek Gite [Last updated: December 13, 2007]

Lighttpd logo

For various reason you might want to redirect all traffic coming to www.domain.com to domain.com or vise versa.

This is essential if you want to maintained good structure for search engines (SEO) or to generate accurate stats.

Configure no www

Open your /etc/lighttpd/lighttpd.conf file:
# vi /etc/lighttpd/lighttpd.conf

Find out your virtual domain section.

Add following configuration directive if you want to redirect www.domain.com to domain.com (no www)

$HTTP["host"] =~ "^www\.(.*)" { url.redirect = ( "^/(.*)" => "http://%1/$1" ) }

Add following configuration directive if you want to redirect domain.com to www.domain.com (force www)

$HTTP["host"] =~ "^domain\.com$" { url.redirect = ( "^/(.*)" => "http://www.domain.com/$1" ) }

Make sure you replace domain.com with your actual domain name. You can see live example of this configuration by visiting this url (it will automatically remove www and redirect you to theos.in domain).

Close and save the file. Restart the lighttpd web server:
# /etc/init.d/lighttpd restart

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. chadrick Says:

    Nice!

    But how do I redirect all feed traffic to a feedburner account?

    If someone make visit to domain.com/feed/ => feeds.feedburner.com/myAccount

    Cheers,

    Chadrick

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.