[Solved] Valid redirection to https by excluding a directory
Added by nti almost 7 years ago
Hi
I want to exclude the directory from redirection to https where Lets-Encrypt sends his code over http to proof the URL. Support told me, that this two examples are not correct syntax, but I have no better idea.
Maybe anyone has a solution for redirect all requests to https except one directory?
$HTTP["host"] =~ "(domain.tld|www.domain.tld)" { alias.url += ("/.well-known/acme-challenge/" => "/var/www/letsencrypt/.well-known/acme-challenge/") $HTTP["url"] !~ "^/\.well-known/acme-challenge/" { url.redirect-code = 301 url.redirect = (".*" => "https://%0$0") } }
Or
$HTTP["host"] =~ "(domain.tld |www.domain.tld)" { alias.url += ("/.well-known/acme-challenge/" => "/var/www/letsencrypt/.well-known/acme-challenge/") $HTTP["url"] !~ "^/\.well-known/acme-challenge/" { url.redirect-code = 301 url.redirect = ( "^/(.*)" => "https://%1:443/$1" ) }
Replies (2)
RE: [Solved] Valid redirection to https by excluding a directory - Added by gstrauss almost 7 years ago
Repeating from #2892
Please see the documentation to understand why your syntax is invalid. Docs_ModRedirect
I think this syntax, which works in lighttpd 1.4.40 and later, will do what you're trying to do:
$HTTP["scheme"] == "http" { $HTTP["host"] =~ "(domain.tld|www.domain.tld)" { url.redirect-code = 301 url.redirect = ( "^/\.well-known/acme-challenge/" => "", # instead of (nonsensical) redirect loop, this matched url will not be modified "^(.*)" => "https://%0$0" ) alias.url += ("/.well-known/acme-challenge/" => "/var/www/letsencrypt/.well-known/acme-challenge/") } } else $HTTP["scheme"] == "https" { $HTTP["host"] =~ "(domain.tld|www.domain.tld)" { alias.url += ("/.well-known/acme-challenge/" => "/var/www/letsencrypt/.well-known/acme-challenge/") } }
The upcoming lighttpd 1.4.50 aims to add some syntactic sugar to make some of this even simpler.
RE: [Solved] Valid redirection to https by excluding a directory - Added by nti almost 7 years ago
Thanks a lot! You've saved my day...