How to redirect www to no-www in Lighttpd

This is pretty easy and is more of a personal note. First check that mod_redirect is enabled in lighttpd.conf:

[code lang=”bash”]sudo nano /etc/lighttpd/lighttpd.conf[/code]

Uncomment the line that write “mod_redirect”.

[code lang=”bash”]server.modules = (

Then add the following at the bottom of your lighttpd.conf:

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

Finally, give lighttpd a restart and test it out:

[code lang=”bash”]sudo /etc/init.d/lighttpd restart[/code]

Hope it helps.

After I made the switch to Lighty, I totally forgot to do redirect all my www sites to no-www, this results in all people who visit to be shown the default site which is what you see here basically.

Finally did some permenant redirection work

This is long overdue work, just one line, okay two lines of code, but it took me two months to get this done. I always wanted to redirect to because some people prefer to type ‘justrealized’ and hit CTRL+Enter on their browsers.

Anyway, this is more of a personal note. To do a permanent redirect using htaccess, you create a file called ‘.htaccess’ with the dot in front and upload it to your Apache web server. Make sure you have the modrewrite enabled. Put the following lines into your .htaccess file and change to your new domain.

[code lang=”apache”]RewriteEngine on
RewriteRule (.*)$1 [R=301,L][/code]

301 means permanent redirect. There are lots of ways to do permanent redirects but .htaccess is the most straight forward method if you have the mod_rewrite working for you.


This redirects all your old URLs to your new domain.