Nixtren
(Nixtren)
June 11, 2016, 1:51pm
1
Hey guys,
Does anyone here know how to trigger a 403 Forbidden error for a certain directory? Imagine I want to block:
/files
How can I block access to that directory? I don’t want to use authentication, just completely block it (like .htaccess “Deny from all”).
Thanks for reading
1 Like
matt
(Matt Holt)
June 11, 2016, 2:58pm
2
Remove read permissions from it: chmod -r files
Nixtren
(Nixtren)
June 11, 2016, 3:23pm
3
But that prevents PHP from reading the files inside it, right? I need PHP to read some of the files inside that folder while blocking people from accessing it directly.
matt
(Matt Holt)
June 11, 2016, 3:28pm
4
Oh, so is this a PHP question?
(Did you look at the rewrite directive?)
Nixtren
(Nixtren)
June 11, 2016, 3:32pm
5
Imagine I have a db.sqlite
file, I want to block direct access to that file while still allowing PHP to open it. Hope it’s more clear now
I managed to achieve a pretty hackish rewrite to rewrite all requests against /files
to 403.html
, but I was looking for a more proper solution.
Edit: Nevermind, I just found out I can trigger a “403 Forbidden”:
rewrite {
regexp ^/files
status 403
}
Thanks for the help
2 Likes
matt
(Matt Holt)
June 11, 2016, 4:06pm
6
I don’t even think you need a regular expression:
status 403 /files
5 Likes
matt
(Matt Holt)
August 7, 2016, 2:50am
7
If people are doing that ^ frequently enough, we could make it a new directive. ext
is already just a special case of rewrite
because it’s very common and useful.
forbid <path>
or, for 404:
hide <path>
Like ext
, these would be small middlewares. … Anyway, just a thought.
2 Likes
abiosoft
(Abiola Ibrahim)
August 7, 2016, 7:24am
8
Or internal
can support status codes instead. e.g. internal /files 403
matt:
If people are doing that ^ frequently enough, we could make it a new directive. ext is already just a special case of rewrite because it’s very common and useful.
forbid <path>
or, for 404:
hide <path>
Like ext, these would be small middlewares. … Anyway, just a thought.
system
(system)
Closed
November 5, 2016, 7:24am
9
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.