Question

I'd like a lighttpd server to redirect/rewrite visitors to a specific page when they come through a subdomain. Here is the example.

Website up and running:

www.example.com

Target page of said website:

www.example.com/subpage

Subdomain that I'd like to have pointed at the target page:

www.sub.example.com

So when a visitor types in : www.sub.example.com I'd like the browser to display the content from www.example.com/subpage

Is this possible? If so can you please explain to me how exactly?

I've tried fiddling with the vhost.conf file but to no avail. Here's what I tried:

$HTTP["host"] =~ "sub\.example\.com" {
server.document-root = "/var/www/example.com/www/"
server.error-handler-404 = "/index.php" 

index-file.names   = ( "/subpage" )

}

Thanks for any advice in advance!

Was it helpful?

Solution

One way to do it is use the url.redirect feature, to redirect www.sub.example.com to www.example.com/subpage

$HTTP["host"] =~ "example.com" {
     $HTTP["host"] =~ "www.sub.example.com" {
          url.redirect = (
             "(.*)" => "http://www.example.com/subpage"
          )
     }
     else $HTTP["host"] =~ "www.example.com" {
         server.document-root = "/var/www/example.com/www/"
         server.error-handler-404 = "/index.php"
     }
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top