Lighttpd redirect www.domain.com requests to domain.com or vice versa
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:
- Lighttpd: redirect feed traffic to a Feedburner account
- How To Lighttpd Create Self Signed SSL Certificates
- nixCraft FAQ Roundup ~ July, 3, 2007
- Lighttpd block wget useragent for specific urls
- Lighttpd: How do I use more than two IP address (bind) for virtual hosting?
Discussion on This Article:
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!
Tags: configuration directive, configure no www, force www, host domain, host www, lighttpd, redirect www, search engines, seo, virtual domain, web server



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