Project

General

Profile

Permanent redirect of subdomains to www. in lighttpd?

Added by kaah over 14 years ago

I want to redirect all subdomain paths on domainxyz.com to www.domainxyz.com except for cdn.domainxyz.com and ad.domainxyz.com.

To clarify: I want for example abc.domainxyz.com/cat.php?id=23 redirect to www.domainxyz.com/cat.php?id=23.

How do I do this in lighttpd?


Replies (3)

RE: Permanent redirect of subdomains to www. in lighttpd? - Added by darix over 14 years ago

$HTTP["host"] == "ad.example.com" {
}
else $HTTP["host"] == "cdn.example.com" {
}
else $HTTP["host"] == "www.example.com" {
}
else $HTTP["host"] =~ "(.*)\.example\.com" {
    url.redirect = (  ".*" => "http://www.example.com$0" )
}

RE: Permanent redirect of subdomains to www. in lighttpd? - Added by jlove over 14 years ago

Will this work with 4th level subdomains? I'm running into a situation where users are sticking www in front of a subdomain and I need to remove the www so that www.subdomain.domain.com redirects to subdomain.domain.com? I'm using the code above and it works great for 3 level domains, but as soon as I try to match a 4th level, it doesn't match the host.

    (1-3/3)