apremalal
(Apremalal)
1
Hello Community,
I need to exclude direct access to some file extensions (.html). I tried to use the following configuration and it doesn’t block direct access.
localhost:{$CAPTIVE_CADDY_PORT}/portal {
ext !.html
root webapps/portals/
gzip
log logs/caddyaccess.log
fastcgi / 127.0.0.1:9000 php
}
Is this achievable with caddy?
There’s two ways to achieve what you’re after.
- Use the
internal
directive to mark paths unavailable to outside requests (see docs for internal)
- Rewrite requests that end in
.html
to some forbidden path
Option 2 looks something like this:
example.com {
status 403 /forbidden
rewrite {
if {path} ends_with .html
to /forbidden
}
}
You can stack extensions to deny like so:
rewrite {
if {path} ends_with .html
if {path} ends_with .php
if_op or
to /forbidden
}
See rewrite docs and status docs.
1 Like
apremalal
(Apremalal)
3
This is helpful. Thanks for the infromation.
system
(system)
Closed
4
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.