How to make a directory not show up for the end user?

Hi! Is there any good way to make a directory inaccessible in the web browser? Let’s say I have a “drafts” folder in my content folder for example and don’t want it to show up even if someone navigates to it in their browser; how could I do this?

Sorry if this is a stupid question.

But you would still like to access them as an admin?
Or making these directories/pages completely inaccessible?

It’s not a stupid question at all. One simple way to solve this would be to add a draft field to your content file and set it to true:

title: My secret article
----
draft: true
----
text: ....

You could then ask in your article template for the draft status and redirect to an error page for example.

<?php if($page->draft()->bool()) go('error') ?> 
<?php snippet('header') ?>
…

You could even extend this to still show the page for logged in users coming from the panel:

<?php if($page->draft()->bool() and !$site->user()) go('error') ?> 
<?php snippet('header') ?>
…
2 Likes

@distantnative For now it will be enough if they are completely inaccessible.

@bastianallgeier Thanks, that makes a lot of sense! I wasn’t sure wether this was something you’d solve via Kirby or if I’d have to go the htaccess route. PHP is not my best suit. Anyway, your suggestion seems like a great way to go. Big thanks!

You could go with htaccess, but personally I was thinking in the same direction as the one Bastian pointed out.