Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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