# Issue with u() and localhost port

**URL:** <https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873>\
**Category:** Questions\
**Tags:** v2\
**Created:** [November 28, 2016, 7:25am UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873 "2016-11-28T07:25:54Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [November 28, 2016, 7:25am UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/1 "2016-11-28T07:25:54Z")

</div>

I have an issue reported here [https://github.com/jenstornell/kirby-panel-flags/issues/1](https://github.com/jenstornell/kirby-panel-flags/issues/1)

**It’s clear that from the image the domain name is missing:**

```plaintext
http://localhost:5757/assets/plugins/kirby-panel-flags/icons/pt.svg

```

**The code that make this is:**

```php
$url = u() . '/assets/plugins/kirby-panel-flags/icons/' . $filename . '.svg'

```

**Shouldn’t `u()` give the installation url, like:**

```plaintext
http://localhost:5757/my-domain.com

```

_(I know that I should probably use `kirby()->urls()->assets()` for it in this case)_

---

<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:** [November 28, 2016, 7:10pm UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/2 "2016-11-28T19:10:06Z")

</div>

To be honest I don’t understand the issue. `http://localhost:5757` is a perfectly valid domain name. It just all depends on the setup.

---

<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:** [November 28, 2016, 7:29pm UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/3 "2016-11-28T19:29:06Z")

</div>

I tested this a well without the port number on localhost, but the resulting url - while correct according to the docs - just doesn’t work, so I don’t think this is related to the port.

Edit: When I uncommented these two rules in .htaccess, it worked:

```auto
# block all files in the site folder from being accessed directly
# except for requests to plugin assets files
RewriteRule ^assets/plugins/([a-zA-Z0-9\.\-_%=]+)/(.*)$ site/plugins/$1/assets/$2 [L,N]
RewriteCond $1 !^plugins/[a-zA-Z0-9\.\-_%=]+/assets/.*

```

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [November 28, 2016, 9:15pm UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/4 "2016-11-28T21:15:28Z")

</div>

@jenstornell:

If you change

> [@jenstornell](#):
>
> u()

to [$site-\>url()](https://getkirby.com/docs/cheatsheet/site/url), you may get what you want or need.  
I don’t know you webserver configuration, but on my “XAMPP on Windows server” and the respective live linux server this runs.

If you want to know why I can suggest this here, you can look at the “gear wheel” links at [HowTo: Working with contextual links to the panel](https://forum.getkirby.com/t/howto-working-with-contextual-links-to-the-panel/1566), where I have used this.

Good luck!

---

<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:** [November 28, 2016, 9:21pm UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/5 "2016-11-28T21:21:04Z")

</div>

@anon77445132: The problem is **not** that the generated URL is wrong. Therefore, unfortunately, `$site->url()` does not solve the problem at all.

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [November 28, 2016, 9:30pm UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/6 "2016-11-28T21:30:25Z")

</div>

@texnixe:  
May be I am wrong, because it may be that I do not understand the **core** problem of @jenstornell, but I think, _if he would change his code_, he will get what he wants or needs.

I think, not every code part of Kirby needs to fit all wishes of all developers…, I feel certain, I can tell your Kirby team many points, I wish to run in another way, but that is different from this question.

Sometimes a developer can avoid some problems…

---

<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:** [November 28, 2016, 9:53pm UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/7 "2016-11-28T21:53:15Z")

</div>

Well, just compare the following two screenshots:

As you will see, the generated URL to the image is perfectly alright:

Image 1: the two lines in .htaccess commented out:

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/7/7f298937c2083271b603aa848fd634e14d2be55c.png)

Image 2: same story, the two lines in .htaccess uncommented:

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/5/57918092e533d0664b1ec7fe70a18ca8267d383b.png)

As you can see, the URL has not changed from image 1 to image 2. So the URL is not the problem.

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [November 28, 2016, 10:02pm UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/8 "2016-11-28T22:02:07Z")

</div>

To answer the first question from @jenstornell on this webpage:  
I am quite sure, that

```php
$site->url()

```

will answer with

> [@jenstornell](#):
>
> [http://localhost:5757/my-domain.com](http://localhost:5757/my-domain.com)

if the website is installed in a directory called `my-domain.com` and the `localhost` webserver `listen`s on port `5757`.

---

<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:** [November 28, 2016, 10:09pm UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/9 "2016-11-28T22:09:41Z")

</div>

@anon77445132: Have you tested this?

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [November 28, 2016, 10:10pm UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/10 "2016-11-28T22:10:22Z")

</div>

No, but I use this on my XAMPP dev system every day, e.g. an extended version of [https://forum.getkirby.com/t/howto-working-with-contextual-links-to-the-panel/1566](https://forum.getkirby.com/t/howto-working-with-contextual-links-to-the-panel/1566).

---

<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:** [November 28, 2016, 10:11pm UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/11 "2016-11-28T22:11:45Z")

</div>

Well, then please **do** test it with the plugin, and you will see that it will not work.

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [November 29, 2016, 8:19am UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/13 "2016-11-29T08:19:12Z")

</div>

I just tested this in Kirby 2.4.0 (without port):

```php
echo $site->url();
echo u();

```

**It gives:**

```nohighlight
http://localhost/kirby/2.4.0
http://localhost/kirby/2.4.0

```

In case it has not changed in Kirby 2.4.1 there is nothing wrong here. They output the same thing.

_(Because my CLI does not work at the moment I use Kirby 2.4.0)_

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [November 29, 2016, 8:26am UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/14 "2016-11-29T08:26:24Z")

</div>

[https://getkirby.com/docs/developer-guide/plugins/assets](https://getkirby.com/docs/developer-guide/plugins/assets)

Now I tried it with the plugin and it did not work. The url I get is this:

[http://localhost/kirby/2.4.0/assets/plugins/kirby-panel-flags/icons/gb.svg](http://localhost/kirby/2.4.0/assets/plugins/kirby-panel-flags/icons/gb.svg)

> http://{domain}/assets/plugins/{pluginName}/{optionalSubfolder}/{filename}

I agree with @texnixe that it is correct according to the docs. Maybe it’s time to add it as an issue to Github?

---

<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:** [November 29, 2016, 8:32am UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/15 "2016-11-29T08:32:17Z")

</div>

If we just leave the plugin aside for a moment, if you just take the resulting URL and copy it into the address bar of your browser, you get this:

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/3/3487f051ee75f20c250b93475c21d47663019ce1.png)

If you change the two lines above in .htaccess, the result is this:

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/8/875a64b331d863f9df7dc3a9d84c245315ae3197.png)

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [November 29, 2016, 8:38am UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/16 "2016-11-29T08:38:45Z")

</div>

Yes, then it works for me too. 🙂

But this should be uncommented in the htaccess by default right? So we can use plugin assets without these kinds of problems?

---

<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:** [November 29, 2016, 8:41am UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/17 "2016-11-29T08:41:48Z")

</div>

Well, I guess, it happens because this line

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

```

blocks all access to the `/site` folder, so maybe it is not surprising that the route does not work.

**Edit** : As I said before, the problem is not caused by `u()` or ports. If you use `panel()->site()->url()` instead of `u()` the result is the same.

I don’t know if it should be uncommented by default. It might suffice to mention it in the docs.

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [November 29, 2016, 8:51am UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/18 "2016-11-29T08:51:09Z")

</div>

Alright!

**I added an issue about it:**

> <https://github.com/getkirby/kirby/issues/520>

---

<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, 4:54pm UTC](https://forum.getkirby.com/t/issue-with-u-and-localhost-port/5873/19 "2025-02-06T16:54:40Z")

</div>

Archived on February 6, 2025, 4:54pm UTC


