1

I want to redirect all non-www to www on my domain.

But when I use this code provided by some websites, and do a graceful restart of the lighttpd server, my website doesn't function anymore - at all:

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

But when I use the one provided at lighttpd's wikipedia page, it works, but it redirects everything example.com/ANYTHINGHERE to www.example.com, i.e. example.com/search.php?v=michael is redirected to www.example.com:

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

I have remembered to include mod_redirect in the config file. Can anyone help me? :-)

2

In the first example you are messing with all type of quotation marks. Only " ", "programmer’s" quotes, are recognized as quotes in configuration files. You configuration now has curved quotes (”, “) and even Chinese style prime quotation mark (″).

You could try this

$HTTP["host"] == "example.com" {
  url.redirect  = (
    "^/(.*)" => "http://www.example.com/$1",
  )
}
  • It still redirects me to www.example.com, unfortunately. :-/ – AnonymousJ Mar 14 '15 at 10:12
  • I tried to simplify it a bit more. Tell me if it works. I'm more familiar with Apache's mod_rewrite syntax. – Esa Jokinen Mar 14 '15 at 10:20
  • The simplified version worked! But how come? What difference does it make to have $HTTP["host"] == "example.com" VS. $HTTP["host"] =~ "^example\.com$". What does the ~, ^, \ and $ do? – AnonymousJ Mar 14 '15 at 10:27
  • == is used for string equal match and =~ for perl style regular expression match. In this case regular expression is not necessary since the case is rather simple. In the regex, ^ states beginning of string and $ end of string. – Esa Jokinen Mar 14 '15 at 10:32
  • Okay. Thanks for the help and the explanation! :-) – AnonymousJ Mar 14 '15 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.