# Htaccess setup subfolder

**URL:** <https://forum.getkirby.com/t/htaccess-setup-subfolder/11897>\
**Category:** Questions\
**Tags:** v2\
**Created:** [December 28, 2018, 5:13pm UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897 "2018-12-28T17:13:50Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmedveckyh](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@jmedveckyh](https://forum.getkirby.com/u/jmedveckyh)\
**Post date:** [December 28, 2018, 5:13pm UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/1 "2018-12-28T17:13:50Z")

</div>

Hello,  
I’m having a problem with a kirby website on a [wedos.com](http://wedos.com) hosting.

The folder structure configured by this webhosting provider is as follows: [Webhosting - Samostatné weby pro aliasy (multihosting) - Znalostní báze WEDOS](https://kb.wedos.com/cs/webhosting/samostatne-weby-aliasy.html)

I apologise that its only in czech language but this is a really popular provider in czech republic so i think it might be helpful if this gets solved also for other people having the same problem in the future.

Basically if I login to FTP I need to upload all the files into a folder `www/domains/mydomain.com/` and it shows up at `mydomain.com` publicly. This is where i put all the kirby files.

The website shows at `mydomain.com` but all the links point to `mydomain.com/domains/mydomain.com/link`

For example `$site->homepage()->url()` points to `mydomain.com/domains/mydomain.com`  
Panel can be found at `mydomain.com/domains/mydomain.com/panel`  
Content page at `mydomain.com/domains/mydomain.com/my-content-page`  
and so on.

The website is not broken and everything works as it should, just all the links are ugly.

I tried to change the rewrite base in kirby’s .htacess file to `/` or `/domains/mydomain.com` but without any success.

The only thing that worked was setting `c::set('url', 'http://mydomain.com');`  
It fixed all the links but now the panel is not reachable, both `mydomain.com/panel` or `mydomain.com/domains/mydomain.com/panel` say Invalid panel URL.

Thank you for any advice

---

<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:** [December 28, 2018, 5:57pm UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/2 "2018-12-28T17:57:31Z")

</div>

Have you tried to set the rewrite base to `/` while setting the URL like you did.

My assumption is that the .htaccess on the root is causing this problem.

---

<div class="post-metadata">

**Author:** ![jmedveckyh](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@jmedveckyh](https://forum.getkirby.com/u/jmedveckyh)\
**Post date:** [December 28, 2018, 6:13pm UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/3 "2018-12-28T18:13:09Z")

</div>

I also think their the root htaccess is going to be the cause ☹  
I did like you said but this still outputs the Invalid Panel URL message, although the Gui is already like panel’s.

 ![15460207252768258348771172511977](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/2/28478b9b8763030e7b62246200e5b1201e14f3c4.jpeg)

---

<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:** [December 28, 2018, 6:25pm UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/4 "2018-12-28T18:25:15Z")

</div>

Hm, isn’t there any other way to assign Domains to subfolders than through the .htaccess? Are you using multiple domains on that hosting?

---

<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:** [December 29, 2018, 11:17am UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/5 "2018-12-29T11:17:22Z")

</div>

Does that error appear before or after logging in?

---

<div class="post-metadata">

**Author:** ![jmedveckyh](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@jmedveckyh](https://forum.getkirby.com/u/jmedveckyh)\
**Post date:** [December 29, 2018, 1:02pm UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/6 "2018-12-29T13:02:34Z")

</div>

Im not using multiple domains right now but i cant guarantuee it will not be the case in the future. Also im not a big expert in .htaccess syntax so i dont know if it can be assigned somehow differently. The actual file used by the hosting is attached in the link in the first post.

And the error page appears before logging in. Even if i add manually /login to the url the error is still there.

---

<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:** [December 29, 2018, 1:16pm UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/7 "2018-12-29T13:16:13Z")

</div>

@lukasbestle Is this kind of setup supported at all?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [December 29, 2018, 7:33pm UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/8 "2018-12-29T19:33:00Z")

</div>

The setup is quite similar to the one of the German hosting provider Uberspace, where Kirby works just fine.

What you could try is the following:

1. In the `/www/.htaccess` file, delete the `[DPI]` flags after the first two `RewriteRules`.
2. In the `/www/domains/mydomain.com/.htaccess` file, set `RewriteBase /`.

Maybe that works. 🙂

---

<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:** [December 29, 2018, 10:59pm UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/9 "2018-12-29T22:59:15Z")

</div>

@lukasbestle Ah, I didn’t know they have a similar setup. Thanks for your answer.

---

<div class="post-metadata">

**Author:** ![jmedveckyh](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@jmedveckyh](https://forum.getkirby.com/u/jmedveckyh)\
**Post date:** [December 30, 2018, 4:40am UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/10 "2018-12-30T04:40:00Z")

</div>

Oh, sounds promising! I’ll try this as soon as i get back to work computer and tell you if it worked.  
Thank you both so far.

---

<div class="post-metadata">

**Author:** ![jmedveckyh](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@jmedveckyh](https://forum.getkirby.com/u/jmedveckyh)\
**Post date:** [January 18, 2019, 10:03am UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/11 "2019-01-18T10:03:35Z")

</div>

Sorry for taking so long to reply. I set it up as you suggested and it unfortunately still doesn’t work ☹ Everything behaves the same way as before.

---

<div class="post-metadata">

**Author:** ![jmedveckyh](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@jmedveckyh](https://forum.getkirby.com/u/jmedveckyh)\
**Post date:** [January 18, 2019, 10:18am UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/12 "2019-01-18T10:18:13Z")

</div>

Could maybe this be of any help? [https://translate.google.com/translate?sl=cs&tl=en&u=https%3A%2F%2Fkb.wedos.com%2Fcs%2Fwebhosting%2Faliasy-chybne-url.html](https://translate.google.com/translate?sl=cs&tl=en&u=https%3A%2F%2Fkb.wedos.com%2Fcs%2Fwebhosting%2Faliasy-chybne-url.html)

It says that the php applications should retrieve current urls using \_SERVER["REQUEST\_URI"] instead of \_SERVER[“PHP\_SELF”] or $\_SERVER[“SCRIPT\_NAME”].

Might this be the case of kirby?

---

<div class="post-metadata">

**Author:** ![jmedveckyh](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@jmedveckyh](https://forum.getkirby.com/u/jmedveckyh)\
**Post date:** [February 25, 2020, 9:05am UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/13 "2020-02-25T09:05:31Z")

</div>

In case anyone finds themselves in the same situation. I browsed the source code of kirby and realized $\_SERVER[“SCRIPT\_NAME”] is actually used in many places and I wasn’t able to identify where exactly to change it. So in the end I changed it to not include the domains folder path before even launching Kirby and it seems like it fixed my issue without breaking anything (panel and urls work the way you expect)!

All you need to do is add this line

`$_SERVER['SCRIPT_NAME'] = preg_replace('/\/domains\/' . $_SERVER['HTTP_HOST'] . '/', '', $_SERVER['SCRIPT_NAME']);`

to the top of index.php file at the root of your kirby project - BEFORE calling `echo (new Kirby)->render();` (or `echo $kirby->launch();` back in Kirby 2). Hope this helps.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:22pm UTC](https://forum.getkirby.com/t/htaccess-setup-subfolder/11897/14 "2025-02-06T17:22:43Z")

</div>

Archived on February 6, 2025, 5:22pm UTC


