1

I need to permanently redirect all www.domain.com to domain.com in Lighttpd.

Here's relevant part of my lighttpd.conf:

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

$HTTP["host"] =~ "(^|\.)domain\.com$" {
     ...
     url.rewrite-once = (
         ...
         "^(/.*)$" => "/mysite.fcgi$1",
     )
}

Problem is that all URLs like http://www.domain.com/blah/ get redirected to http://domain.com/mysite.fcgi/blah/

I need the "mysite.fcgi" rewrite rule since it sends the request to fastcgi instance.

How do I redirect properly?

2

If you need to redirect all requests made to www.domain.com/ regardless of the request path, just drop the $1 at the end of the third line so it looks like this:

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

$1 is substituted with the first match of the ^/(.*) regular expression, which is, in your case, is everything after the first slash.

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.