Reputation: 2548
I'm trying to redirect an ipaddress-as-URL to the formal hostname as URL:
debug.log-request-handling = "enable"
debug.log-request-header = "enable"
debug.log-response-header = "enable"
debug.log-ssl-noise = "enable"
debug.log-condition-handling = "enable"
$HTTP["host"] == "192.168.1.20" {
url.redirect = ( ".*" => "http://pihole.home.lan/" )
}
But it doesn't work. Relevant log entries:
2019-02-26 13:01:35: (request.c.436) fd: 10 request-len: 331 \nGET / HTTP/1.1\r\nHost: 192.168.1.20\r\nUser-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\nUpgrade-Insecure-Requests: 1\r\n\r\n
2019-02-26 13:01:35: (response.c.261) run condition
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.557) SERVER["socket"] ( :80 ) compare to [::]:80
2019-02-26 13:01:35: (configfile-glue.c.615) 1 (uncached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.557) HTTP["url"] ( / ) compare to ^/admin/
2019-02-26 13:01:35: (configfile-glue.c.615) 2 (uncached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.350) go parent global/HTTPurl=~^/admin/
2019-02-26 13:01:35: (configfile-glue.c.622) 2 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.615) 3 (uncached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.557) HTTP["url"] ( / ) compare to ^/admin/\.(.*)
2019-02-26 13:01:35: (configfile-glue.c.615) 4 (uncached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.557) HTTP["host"] ( 192.168.1.20 ) compare to 192.168.1.20
2019-02-26 13:01:35: (configfile-glue.c.615) 5 (uncached) result: true
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.557) HTTP["host"] ( 192.168.1.20 ) compare to pihole($|\.home\.lan)
2019-02-26 13:01:35: (configfile-glue.c.615) 6 (uncached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.350) go parent global/HTTPhost=~pihole($|\.home\.lan)
2019-02-26 13:01:35: (configfile-glue.c.622) 6 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.615) 7 (uncached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.350) go parent global/HTTPhost=~pihole($|\.home\.lan)
2019-02-26 13:01:35: (configfile-glue.c.622) 6 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.615) 8 (uncached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.350) go parent global/HTTPhost=~pihole($|\.home\.lan)/HTTPscheme==http
2019-02-26 13:01:35: (configfile-glue.c.622) 8 (cached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.615) 9 (uncached) result: skipped
2019-02-26 13:01:35: (response.c.350) -- splitting Request-URI
2019-02-26 13:01:35: (response.c.351) Request-URI : /
2019-02-26 13:01:35: (response.c.352) URI-scheme : http
2019-02-26 13:01:35: (response.c.353) URI-authority : 192.168.1.20
2019-02-26 13:01:35: (response.c.354) URI-path (raw) : /
2019-02-26 13:01:35: (response.c.355) URI-path (clean): /
2019-02-26 13:01:35: (response.c.356) URI-query :
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 1 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 2 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 3 (cached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 4 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 5 (cached) result: true
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 6 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 7 (cached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 8 (cached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 9 (cached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 1 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 2 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 3 (cached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 4 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 5 (cached) result: true
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 6 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 7 (cached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 8 (cached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 9 (cached) result: skipped
2019-02-26 13:01:35: (mod_access.c.148) -- mod_access_uri_handler called
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 1 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 2 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 3 (cached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 4 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 5 (cached) result: true
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 6 (cached) result: false
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 7 (cached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 8 (cached) result: skipped
2019-02-26 13:01:35: (configfile-glue.c.694) === start of condition block ===
2019-02-26 13:01:35: (configfile-glue.c.622) 9 (cached) result: skipped
2019-02-26 13:01:35: (response.c.122) Response-Header: \nHTTP/1.1 401 Unauthorized\r\nContent-Type: text/html\r\nContent-Length: 351\r\nDate: Tue, 26 Feb 2019 21:01:35 GMT\r\nServer: lighttpd/1.4.45\r\n\r\n
This part of the log shows the test for HOST as 192.168.1.20 returning true:
HTTP["host"] ( 192.168.1.20 ) compare to 192.168.1.20
5 (uncached) result: true
However, the redirect doesn't seem to take place, and the next action is return unauthorized 401.
I think I am missing something basic.
Upvotes: 0
Views: 1090
Reputation: 2404
mod_auth is likely loaded before mod_redirect in your config file and so the authentication requirement is applied to the request before the redirect. This is often very desirable behavior in order to avoid leaking information about the redirect to unauthorized users. If you want to perform the redirect first, then set a condition on which to apply the redirect, and apply the authentication requirement to everything else.
$HTTP["host"] == "192.168.1.20" {
url.redirect = ( "" => "http://pihole.home.lan/" )
}
else {
auth.require = ( ... )
}
Based on your multiple posts, it is clear that you are trying to create a configuration more complex than your basic understanding. Before posting more and more and more and more and more and more questions, please test a simple configuration with what you are trying to do. Once you get it working to do a single, simple thing all by itself, only then should you consider adding it to your existing configuration, and testing again. If it works, great. If it does not work, please spend some effort troubleshooting on your own before posting more questions and making people guess about your configuration, which I will note that you have not provided. Your peers on the internet are not clairvoyant. We are just often better at troubleshooting (e.g. following the simple, basic steps just mentioned).
Upvotes: 2