.htaccess RewriteBase not working

I have my kirby website in a subfolder and already changed the Rewritebase in my htaccess, but the images are not being loaded on my site.

When I turn on the RewriteBase, the entire site breaks and it says Error 403, Forbidden.
As soon as I turn off RewriteBase, the site works but images cannot load.

My domain is redirecting to /html and I also tried to set RewriteBase to /sites/new and /new

Is there anything I am doing wrong?

.htaccess:


AddHandler x-httpd-php8.0 .php
# Kirby .htaccess
# revision 2020-06-15

# 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 /html/sites/new

# 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>

Is anything created in the /media folder or is the media folder created at all?

The media folder exists and the console is telling me:

Failed to load resource:(http://www.mywebsite.com/neu/media/pages/project-a/dreams/70e67dc920-1647263001/2a-1200x800.jpg) the server responded with a status of 404 (Not Found)

I noticed, that there is no folder like “70e67dc920-1647263001” and the website created folders by itself on the ftp server when I load the website…

But there are images in the media folder, for example "media/pages/project-a/dreams/0b0746fcc5-1644230813/4-1200x800.jpg

This looks good in general. What if you delete the media folder so that all files are recreated?

I deleted the media folder, but it keeps creating emtpy folders inside its new, self created media folder. But it has successfully created every project folder and each page folder inside /media.

Kirby copies media files from the content folder into the media folder and also creates thumbs for images if you call the thumb/crop/resize etc. methods.

For thumbs, Kirby creates json job files first which are then created on the fly when the URL to a thumb is called.

When the Panel and subpages of your installation work (is that the case), then we don’t have a problem with rewriting and won’t have to look into this, but rather look into why files are not generated.

Hmm, so the page has no subpages, so I cannot test this. But I can’t open the panel. It says „Not found“

Also, the site works perfectly on another server where it also was located in a subfolder…

To get this right: Your domain points to the html folder? And then you have two subfolder below that? Could you outline the structure?

What if you point a subdomain to the folder where Kirby is located? Does it work then?

Yes, the domain is directing to /html and the kirby folders are in /html/sites/new.
When I set a subdomain to this directory, it is the exact same problem :confused:

Have you tried if RewriteBase /html/sites/new/ (trailing slash) works? Not sure if it makes the difference but worth a try.

Thanks, @helloanselm, but unfortunately leads to the same “403 Forbidden” Error…

Maybe a few more details:
The server runs on php version 5.2, so I set the version of the kirby folder to 8.0 with the first line in my .htaccess

AddHandler x-httpd-php8.0 .php

I did this to keep the functionality of the rest of the website which maybe is not compatible with php 8.0.
Is there maybe a problem with it?

So, now I tried to set the php version of the entire server to 8.0. I deleted the first line in my .htaccess and tried to set RewriteEngine Off and On with any of those combinations:

RewriteBase /html/sites/new/
RewriteBase /html/sites/new
RewriteBase /html/sites/
RewriteBase /html/sites
RewriteBase /html/
RewriteBase /html
RewriteBase /

But no difference, the website is always displaying Error 403, Forbidden and as soon as RewriteEngine is Off, it shows the entire site but cannot find the images. It creates folders in /media which only contain a .jobs folder but no images.

But what I also noticed: it finds every caption of the images. The caption is a field inside my default image.yml blueprint. So it finds the file somehow, but cannot find the image?! @texnixe is this information helpful?
This was also the case before updating php.

Thank you for any help!

In general, in many cases you don’t have to set the rewrite base at all. But if you had to set it, I think you need to set it in relation to where your domain is pointing to. So if the domain points to /html, the subfolder would be /sites/new/. etc.

Given that you said you also tried to set a subdomain to this directory, I think the issue is somewhere else. If the Panel and subpages don’t work, then likely rewriting is not enabled.

If you point a subdomain to the folder with the kirby project, what is the result? Does the homepage work? But subpages and the panel and images don’t?

Thank you @texnixe,

when I point a subdomain to the kirby folder and turn RewriteBase off, the homepage works as fine as without the subdomain. The images are not being loaded and when I try to open the panel, the page calls “Not found”. As the page has no subpages, I cannot test, if they work.

It totally makes sense, that it would be only “/sites/new/” and I tried all combinations, but it all results in 403, forbidden.

Images, subpages and the Panel all need rewriting to work. With the subdomain approach, we can at least stop worrying about the RewriteBase settings.

Check if URL rewriting is enabled on the server, you can do that with phpinfo(), then check in the “Loaded modules” section.

Thanks, mod_rewrite was indeed turned off in my server properties and I turned it on. When I go to the phpinfo file, I get this table:
(There is no section called “Loaded modules”, the table below has the headline “standard” and something with “url_rewrite” in some of the last lines)


I don’t really know if it is on now, do you see anything helpful here?

By now, the homepage still cannot load images.

Was expecting output like this (maybe not always revealed):

Hm, I don’t see anything similar to this. Also there is nothing when I search on the page for " e.g. “mod”.
Do I have to add something to my phpinfo.php?

<?php
phpinfo();
?>

Where are you hosting?