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

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

How To Configure No www

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

Find out your virtual domain section.

WWW Redirect with lighttpd

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

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

No-WWW Redirect with lighttpd

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

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

Make sure you replace 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 domain).

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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 8 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
8 comments… add one
  • chadrick Aug 5, 2006 @ 11:30


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

    If someone make visit to =>



  • peter Jan 13, 2009 @ 3:18

    How can i redirect user based on referer?
    Sometime i got bad user i want to redirect them to goway.html? How can i do that? In apache i do something like this:

    RewriteEngine On
    Options +FollowSymlinks
    RewriteCond %{HTTP_REFERER} ^http://(.+) [NC,OR]
    RewriteCond %{HTTP_REFERER} ^http://(www.)? [NC,OR]
    RewriteRule ^(.*)$ http://mysitehere/getout.html [R=301,L]

  • Geoff Jan 19, 2009 @ 23:29

    Does anyone know how I can redirect all non-ww domains to the www version?

    I basically need this reversed:

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

    Thanks for any help!

  • Jush Fuskin Jul 17, 2009 @ 15:54

    I added the directive into my .conf file and it worked but the problem is when I visit a url

    for example: when I go to it sends me to Which is what I want.

    But when I go to Instead of adding a www. infront of the title it just redirects me to the instead of

    How do I fix this?

  • 🐧 nixCraft Jul 17, 2009 @ 16:37

    Did you add $1 at the end of domain name?

  • Jush Fuskin Jul 17, 2009 @ 16:54

    Yes I have, here is the exact code I am using.

    $HTTP[“host”] =~ “(^|.)$” {
    url.redirect = ( “^/(.*)” => “$1” )
    server.document-root = “/var/www/html/”
    server.error-handler-404 = “/404.php”

  • Franz Dec 22, 2010 @ 9:40

    How can I enable this for HTTPS, too? This rewrite rule seems to redirect to HTTP automatically.

  • fayaz Apr 8, 2015 @ 14:17

    hey how are you all …
    i have two server which is running at the same time ..and having same pages like CDN network.
    for example. (
    question is that…when user hit above site.they are facing 404 not found..
    i want when ever user face that error it will automatically redirect on my another server for example ( this .and get page from there and they access that automatically ..i will be very thankfull to you act of this kindness
    kindly tell me in this regards ,.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum