# Content folder exposed despite correct htaccess rules

**URL:** <https://forum.getkirby.com/t/content-folder-exposed-despite-correct-htaccess-rules/26747>\
**Category:** Questions\
**Tags:** v3\
**Created:** [October 17, 2022, 8:25am UTC](https://forum.getkirby.com/t/content-folder-exposed-despite-correct-htaccess-rules/26747 "2022-10-17T08:25:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![winstongrace](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/winstongrace/32/12491_2.png) [@winstongrace](https://forum.getkirby.com/u/winstongrace)\
**Post date:** [October 17, 2022, 8:25am UTC](https://forum.getkirby.com/t/content-folder-exposed-despite-correct-htaccess-rules/26747/1 "2022-10-17T08:25:50Z")

</div>

I am getting **The content folder seems to be exposed** and sure enough I can access my site.txt file directly by URL.

The strange thing is I have the correct htaccess rules _and_ these rules work for the `site` and `kirby` folders.

```auto
# block all files in the content folder from being accessed directly
RewriteRule ^content/(.*) index.php [L]

# block all files in the site folder from being accessed directly
RewriteRule ^site/(.*) index.php [L]

# block direct access to Kirby and the Panel sources
RewriteRule ^kirby/(.*) index.php [L]

```

All 3 folders have the same permissions. When I comment out the `site` folder rule, I can access files directly.

I’m stumped.

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [February 15, 2024, 3:35pm UTC](https://forum.getkirby.com/t/content-folder-exposed-despite-correct-htaccess-rules/26747/2 "2024-02-15T15:35:00Z")

</div>

Hi. I’m experiencing this issue too.

 ![ss](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/5/5585a2ae5936687abe435c4bc1c39ab3d3245624.jpeg)

Here’s my .htaccess

```auto
# Kirby .htaccess
# revision 2022-09-15

# rewrite rules
<IfModule mod_rewrite.c>

# enable awesome urls. i.e.:
# http://yourdomain.com/about-us/team
RewriteEngine on

RewriteRule ^site/(.*) index.php [L]

#Force SSL
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# make sure to set the RewriteBase correctly
# if you are running the site in a subfolder;
# otherwise links or the entire site will break.
#
# If your homepage is http://yourdomain.com/mysite,
# set the RewriteBase to:
#
# RewriteBase /mysite

# In some environments it's necessary to
# set the RewriteBase to:
#
# RewriteBase /

# block files and folders beginning with a dot, such as .git
# except for the .well-known folder, which is used for Let's Encrypt and security.txt
RewriteRule (^|/)\.(?!well-known\/) index.php [L]

# block all files in the content folder from being accessed directly
RewriteRule ^content/(.*) index.php [L]

# block all files in the site folder from being accessed directly
RewriteRule ^site/(.*) index.php [L]

# block direct access to Kirby and the Panel sources
RewriteRule ^kirby/(.*) index.php [L]

# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]

</IfModule>

# pass the Authorization header to PHP
SetEnvIf Authorization "(.+)" HTTP_AUTHORIZATION=$1

# compress text file responses
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

```

Hmm… It all seems up to par, but I’m getting those alerts and I can access the files directly in the browser. Is it something with Litespeed instead of Apache?

Any insight would be appreciated.

---

<div class="post-metadata">

**Author:** ![Aafke](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/aafke/32/13419_2.png) [@Aafke](https://forum.getkirby.com/u/Aafke)\
**Post date:** [April 9, 2025, 7:58am UTC](https://forum.getkirby.com/t/content-folder-exposed-despite-correct-htaccess-rules/26747/3 "2025-04-09T07:58:12Z")

</div>

Any insights on this? I also seem to have this issue, locally the rewrite is working but on the server the content dir is still exposed.

The weird thing is that for the site and kirby content it is working.

````auto
# Kirby .htaccess
# revision 2023-07-22

# rewrite rules
<IfModule mod_rewrite.c>

# enable awesome urls. i.e.:
# http://yourdomain.com/about-us/team
RewriteEngine on

# make sure to set the RewriteBase correctly
# if you are running the site in a subfolder;
# otherwise links or the entire site will break.
#
# If your homepage is http://yourdomain.com/mysite,
# set the RewriteBase to:
#
# RewriteBase /mysite

# In some environments it's necessary to
# set the RewriteBase to:
#
# RewriteBase /

# block files and folders beginning with a dot, such as .git
# except for the .well-known folder, which is used for Let's Encrypt and security.txt
RewriteRule (^|/)\.(?!well-known\/) index.php [L]

# block all files in the content folder from being accessed directly
RewriteRule ^content/(.*) index.php [L]

# block all files in the site folder from being accessed directly
RewriteRule ^site/(.*) index.php [L]

# block direct access to Kirby and the Panel sources
RewriteRule ^kirby/(.*) index.php [L]

# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]

</IfModule>

# pass the Authorization header to PHP
SetEnvIf Authorization "(.+)" HTTP_AUTHORIZATION=$1

# compress text file responses
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

# set security headers in all responses
<IfModule mod_headers.c>

# serve files as plain text if the actual content type is not known
# (hardens against attacks from malicious file uploads)
Header set Content-Type "text/plain" "expr=-z %{CONTENT_TYPE}"
Header set X-Content-Type-Options "nosniff"

</IfModule> ```
````

---

<div class="post-metadata">

**Author:** ![stffr](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@stffr](https://forum.getkirby.com/u/stffr)\
**Post date:** [April 9, 2025, 9:05am UTC](https://forum.getkirby.com/t/content-folder-exposed-despite-correct-htaccess-rules/26747/4 "2025-04-09T09:05:01Z")

</div>

I had the same issue, I traced it back to having a rediret via the `go` function in the `default.php` template. But I didn’t have time yet to check what’s the problem…

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [April 9, 2025, 11:49am UTC](https://forum.getkirby.com/t/content-folder-exposed-despite-correct-htaccess-rules/26747/5 "2025-04-09T11:49:44Z")

</div>

> [@stffr](#):
>
> But I didn’t have time yet to check what’s the problem…

If you don’t have a specific `error.php` template for error pages, and the `default.php` template redirects to the home page (or elsewhere) instead of displaying the error page, then any links that should return a 404 error instead of a 301 or 302 redirect won’t work. This causes the system check to fail, as it expects an HTTP error code.

---

<div class="post-metadata">

**Author:** ![Aafke](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/aafke/32/13419_2.png) [@Aafke](https://forum.getkirby.com/u/Aafke)\
**Post date:** [April 15, 2025, 11:48am UTC](https://forum.getkirby.com/t/content-folder-exposed-despite-correct-htaccess-rules/26747/6 "2025-04-15T11:48:30Z")

</div>

Thanks a lot!

It seems to work,if i go to /content/site.txt it is not visible anymore.  
The panel still tells me that “the content folder seems to be exposed” though. Any ideas why that might be?

---

<div class="post-metadata">

**Author:** ![thguenther](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thguenther/32/16708_2.png) [@thguenther](https://forum.getkirby.com/u/thguenther)\
**Post date:** [April 17, 2025, 12:23pm UTC](https://forum.getkirby.com/t/content-folder-exposed-despite-correct-htaccess-rules/26747/7 "2025-04-17T12:23:54Z")

</div>

Are you sure you’re using an Apache web server that can deal with the `.htaccess` file?

If you’re using Nginx for example you might want to have a look at this cookbook: [Kirby meets Nginx | Kirby CMS](https://getkirby.com/docs/cookbook/development-deployment/nginx)

---

<div class="post-metadata">

**Author:** ![jonathannicol](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jonathannicol/32/16880_2.png) [@jonathannicol](https://forum.getkirby.com/u/jonathannicol)\
**Post date:** [November 4, 2026, 6:21am UTC](https://forum.getkirby.com/t/content-folder-exposed-despite-correct-htaccess-rules/26747/8 "2026-11-04T06:21:38Z")

</div>

A PSA for people using Runcloud to manage their server:

Even if your server is configured in Runcloud as a NGINX/Apache hybrid, and supports .htaccess, text files will still be publicly accessible. That’s because some file types, including text files, are passed directly to NGINX for handling, bypassing Apache.

In Runcloud create a new NGINX Config file (which can be done via the Runcloud panel), and add the following line, which is taken from the documentation thguenther linked to in an earlier post:

`rewrite ^/(content|site|kirby)/(.*)$ /error last;`

---

<div class="post-metadata">

**Author:** ![CactusJazz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/cactusjazz/32/16889_2.png) [@CactusJazz](https://forum.getkirby.com/u/CactusJazz)\
**Post date:** [November 11, 2026, 4:36pm UTC](https://forum.getkirby.com/t/content-folder-exposed-despite-correct-htaccess-rules/26747/30 "2026-11-11T16:36:32Z")

</div>

> [@jonathannicol](#):
>
> some file types, including text files, are passed directly to NGINX for handling, bypassing Apache

Same thing can happen on Plesk. In Apache & nginx Settings there’s “Serve static files directly by nginx” with a list of extensions, and if txt is in that list, the .htaccess rules for /content never get a chance. Taking txt out of the list or adding the nginx rewrite like above fixes it.
