# .htaccess RewriteBase not working

**URL:** <https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967>\
**Category:** Questions\
**Created:** [March 14, 2022, 3:12pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967 "2022-03-14T15:12:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobias93](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@tobias93](https://forum.getkirby.com/u/tobias93)\
**Post date:** [March 14, 2022, 3:12pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/1 "2022-03-14T15:12:03Z")

</div>

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:

```auto

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>

```

---

<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:** [March 14, 2022, 4:59pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/2 "2022-03-14T16:59:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tobias93](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@tobias93](https://forum.getkirby.com/u/tobias93)\
**Post date:** [March 14, 2022, 5:17pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/3 "2022-03-14T17:17:04Z")

</div>

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](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

---

<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:** [March 14, 2022, 5:23pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/4 "2022-03-14T17:23:57Z")

</div>

> [@tobias93](#):
>
> 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?

---

<div class="post-metadata">

**Author:** ![tobias93](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@tobias93](https://forum.getkirby.com/u/tobias93)\
**Post date:** [March 14, 2022, 5:31pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/5 "2022-03-14T17:31:07Z")

</div>

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.

---

<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:** [March 14, 2022, 5:40pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/6 "2022-03-14T17:40:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tobias93](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@tobias93](https://forum.getkirby.com/u/tobias93)\
**Post date:** [March 14, 2022, 6:32pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/7 "2022-03-14T18:32:29Z")

</div>

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…

---

<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:** [March 14, 2022, 7:21pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/8 "2022-03-14T19:21:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tobias93](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@tobias93](https://forum.getkirby.com/u/tobias93)\
**Post date:** [March 14, 2022, 10:49pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/9 "2022-03-14T22:49:09Z")

</div>

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 😕

---

<div class="post-metadata">

**Author:** ![helloanselm](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/helloanselm/32/11487_2.png) [@helloanselm](https://forum.getkirby.com/u/helloanselm)\
**Post date:** [March 15, 2022, 5:47am UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/10 "2022-03-15T05:47:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tobias93](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@tobias93](https://forum.getkirby.com/u/tobias93)\
**Post date:** [March 15, 2022, 8:34am UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/11 "2022-03-15T08:34:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tobias93](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@tobias93](https://forum.getkirby.com/u/tobias93)\
**Post date:** [March 15, 2022, 8:37am UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/12 "2022-03-15T08:37:38Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![tobias93](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@tobias93](https://forum.getkirby.com/u/tobias93)\
**Post date:** [March 15, 2022, 11:17am UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/13 "2022-03-15T11:17:58Z")

</div>

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:

```auto
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!

---

<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:** [March 15, 2022, 11:43am UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/14 "2022-03-15T11:43:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tobias93](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@tobias93](https://forum.getkirby.com/u/tobias93)\
**Post date:** [March 15, 2022, 12:12pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/15 "2022-03-15T12:12:13Z")

</div>

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.

---

<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:** [March 15, 2022, 12:28pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/16 "2022-03-15T12:28:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tobias93](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@tobias93](https://forum.getkirby.com/u/tobias93)\
**Post date:** [March 15, 2022, 1:04pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/17 "2022-03-15T13:04:09Z")

</div>

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)

 ![Screenshot 2022-03-15 at 14.00.48](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/7/7eeb0f173e1f0460d87f397a47300e126fdda35c.png)  
I don’t really know if it is on now, do you see anything helpful here?

By now, the homepage still cannot load images.

---

<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:** [March 15, 2022, 4:31pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/18 "2022-03-15T16:31:25Z")

</div>

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

 ![Bildschirmfoto 2022-03-15 um 16.13.20](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/d/dcd05fd8c6ca5d9e1b35a5c699d0e3717a221433.jpeg)

---

<div class="post-metadata">

**Author:** ![tobias93](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@tobias93](https://forum.getkirby.com/u/tobias93)\
**Post date:** [March 15, 2022, 6:24pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/19 "2022-03-15T18:24:37Z")

</div>

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?

```auto
<?php
phpinfo();
?>

```

---

<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:** [March 15, 2022, 6:25pm UTC](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967/20 "2022-03-15T18:25:40Z")

</div>

Where are you hosting?

[Next page](https://forum.getkirby.com/t/htaccess-rewritebase-not-working/24967.md?page=2)
