Regular Expression Matching for lighttpd mod_evhost (www.domain.com/domain.com/sub.domain.com)

I play with lighttpd on a small virtual private server. I have two domains pointing to a server. I am using the latest version of lighttpd and mod_evhost on Ubuntu 8.10.

  • I am trying to configure a rule so that if someone asks for domain.com or www.domain.com , they get a message from /webroot/domain.com/www/

  • Similarly, if someone requests sub.domain.com , he receives a message from /webroot/domain.com/sub/

  • If people request fake.domain.com (where / webroot / domain.com / fake / does not exist), I would like them to be from /webroot/domain.com/www/

The third requirement is not so important, I can deal with people who request subdomains that do not exist, who are served from the root of the server document /webroot/server.com/www/, even if they requested a fake .domain.com

I have included the relevant parts of my lighttpd.conf file below:

server.document-root = "/webroot/server.com/www/"

// regex to match sub.domain.com
$HTTP["host"] =~ "\b[a-zA-Z]\w*\.\b[a-zA-Z]\w*\.\b[a-zA-Z]\w*" {
    evhost.path-pattern = "/webroot/%0/%3/"    
}

// regex to match domain.com    
$HTTP["host"] =~ "\b[a-zA-Z]\w*\.\b[a-zA-Z]\w*" {
    evhost.path-pattern = "/webroot/%0/www/"    
}

So where am I going wrong? At the moment, all requests *. Domain.com and domain.com are run from /webroot/domain.com/www/

I would appreciate any help that you guys could offer, and if I left something interesting, please tell me!

Cheers rob

+3
2

.

:

// regex to match sub.domain.com
$HTTP["host"] =~ "^[^.]+\.[^.]+\.[^.]+$" {
    evhost.path-pattern = "/webroot/%0/%3/"    
}

// regex to match domain.com    
$HTTP["host"] =~ "^[^.]+\.[^.]+$" {
    evhost.path-pattern = "/webroot/%0/www/"    
}

:

[^.]+ matches anything but a dot, 1..n times

"www", :

// default: route everything to "www"
$HTTP["host"] =~ "([^.]+\.)?domain\.com$" {
    evhost.path-pattern = "/webroot/%0/www/"
}

// specific regex overwrites "path-pattern" for valid sub-domains only
$HTTP["host"] =~ "^(valid1|valid2|sub)\.domain\.com$" {
    evhost.path-pattern = "/webroot/%0/%3/"    
}
+5

, domain.com www.domain.com: ^\b([wW]{3}\.)?[\w\d]*\.com\b$, , , /, . , .

+1

Source: https://habr.com/ru/post/1699106/


All Articles