# Base\_url\_no\_prefix actually base\_url\_no\_suffix?

**URL:** <https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797>\
**Category:** Development\
**Created:** [8월 15, 2018, 1:49오후 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797 "2018-08-15T13:49:28Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)\
**Post date:** [8월 15, 2018, 1:49오후 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797/1 "2018-08-15T13:49:29Z")

</div>

Noticed this while cleaning up my CSP proof of concept:

`Discourse.base_url_no_prefix` seems to actually be the base url sans path (not protocol, as I would expect), compare `base_url_no_prefix` to `base_url` below:

> <https://github.com/discourse/discourse/blob/main/lib/discourse.rb#L250-L267>

So, I propose `base_url_no_prefix` is renamed `base_url_no_suffix` or `base_url_no_path` to clear up any future confusion.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [8월 15, 2018, 11:51오후 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797/2 "2018-08-15T23:51:06Z")

</div>

Sure what do you think @neil? Naming is important!

---

<div class="post-metadata">

**Author:** ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)\
**Post date:** [8월 16, 2018, 1:47오전 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797/3 "2018-08-16T01:47:54Z")

</div>

But it’s a prefix to all paths. A path suffix would be strange. I don’t agree that this name is confusing.

---

<div class="post-metadata">

**Author:** ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)\
**Post date:** [8월 16, 2018, 7:39오전 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797/4 "2018-08-16T07:39:30Z")

</div>

> [@LeoMcA](#):
>
> base\_url\_no\_prefix

Seems fine as-is. It’s the base URL without a prefix. Saying no suffix on a base URL is redundant.  
As to no path, that’s just confusing- it’s valid without a path, right?

---

<div class="post-metadata">

**Author:** ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)\
**Post date:** [8월 16, 2018, 12:31오후 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797/5 "2018-08-16T12:31:02Z")

</div>

But surely the method would have to be named `base_url_no_path_prefix` to be able to extract that meaning from it. With no mention of any path, there’s no reason to assume prefix refers to anything other than the _base url’s_ prefix.

Don’t want to labour the point here (though after proofreading I realized I have), but suppose discourse were running from [https://example.com/discourse:](https://example.com/discourse:)

Currently, the methods would produce the following:

`base_uri`: /discourse  
`base_protocol`: https  
`base_url_no_prefix`: [https://example.com](https://example.com)  
`base_url`: [https://example.com/discourse](https://example.com/discourse)

Whereas if I were to take a guess at what they would produce without having read the source:

`base_uri`: ??? could be many many different things  
`base_protocol`: https  
`base_url_no_prefix`: [example.com/discourse](http://example.com/discourse)  
`base_url`: [https://example.com/discourse](https://example.com/discourse)

I humbly propose those methods are renamed like so:

`base_uri` → `base_path`  
`base_protocol` ✓  
`base_url_no_prefix` → `base_url_no_path` (let’s remove any confusion over what prefix/suffix is referring to)  
`base_url` ✓

But maybe my brain works a bit differently, I don’t mind that much - certainly less than the length of this post suggests 🙂

---

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [11월 6, 2018, 1:02오후 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797/6 "2018-11-06T13:02:48Z")

</div>

> [@LeoMcA](#):
>
> But maybe my brain works a bit differently

You are not alone. I _always_ need to look at this post whenever I work with `base_*` stuff.

@neil Any objections to adding @LeoMcA’s suggestions as method aliases? I have to add subfolder support to a bunch of translations and `base_path` would make a lot more sense to me than `base_uri`.

---

<div class="post-metadata">

**Author:** ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)\
**Post date:** [11월 6, 2018, 3:08오후 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797/7 "2018-11-06T15:08:32Z")

</div>

Sure, but I don’t like “base\_url\_no\_prefix” meaning being switched to “remove http://” instead of “remove subfolder”.

> [@LeoMcA](#):
>
> `base_url_no_prefix` → `base_url_no_path`

Let’s use the word subfolder there since we all seem to know what that means. `base_url_no_subfolder`?

---

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [11월 6, 2018, 3:33오후 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797/8 "2018-11-06T15:33:25Z")

</div>

The meaning of `base_url_no_prefix` isn’t switched. It still removes the prefix (=path).

| Method | Alias | Output |
| --- | --- | --- |
| `base_uri` | `base_path` | `/discourse` |
| `base_protocol` | | `https` |
| `base_url_no_prefix` | `base_url_no_path` | `https://example.com` |
| `base_url` | | `https://example.com/discourse` |

I think using “path” instead of “prefix” or “subfolder” works best.

---

<div class="post-metadata">

**Author:** ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)\
**Post date:** [11월 6, 2018, 3:48오후 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797/9 "2018-11-06T15:48:59Z")

</div>

So the code is going to be a mess of some places using `base_url_no_prefix` and some places using `base_url_no_path`, depending on the preference of who writes that code? I’m not a fan of that.

So the changes to existing would be:

`base_uri` becomes `base_path`: looks good to me.  
`base_url_no_prefix` becomes `base_url_no_path`: also looks good.

I say we replace those instead of creating aliases.

I thought @LeoMcA wanted `base_url_no_prefix` to mean removing the “http://” which is a change of value and will cause bugs.

Except plugins might be using them. So maybe not.

---

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [11월 6, 2018, 4:01오후 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797/10 "2018-11-06T16:01:07Z")

</div>

> [@neil](#):
>
> Except plugins might be using them. So maybe not.

I can rename the methods, update our code in core and deprecate the old method names. But yeah, removing them isn’t possible right now because I’m quite sure lots of plugins use them.

---

<div class="post-metadata">

**Author:** ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)\
**Post date:** [11월 6, 2018, 4:21오후 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797/11 "2018-11-06T16:21:28Z")

</div>

> [@neil](#):
>
> I thought @LeoMcA wanted `base_url_no_prefix` to mean removing the “http://” which is a change of value and will cause bugs.

I more meant that that’s what it meant in my head, rather than wanting a method which does that to be named `base_url_no_prefix` (there’s no method named anything which does that currently IIRC).

If there was to be a method I’d suggest it be called `base_url_no_protocol`, but I’m not sure it’s necessary since `current_hostname` and `base_uri` can just be concatenated.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [11월 7, 2018, 1:27오전 UTC](https://meta.discourse.org/t/base-url-no-prefix-actually-base-url-no-suffix/94797/12 "2018-11-07T01:27:38Z")

</div>

`base_url_no_prefix` → `https://example.com`  
`base_url` → `https://example.com/discourse`

Yeah the use of the word prefix here is.. kinda.. wrong @neil? More like `base_url_no_suffix`, amirite?

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/6/969e52ba4c5f6dfb6e4429a18be706e51c392917.jpeg)

> [@neil](#):
>
> `base_uri` becomes `base_path` : looks good to me.  
> `base_url_no_prefix` becomes `base_url_no_path` : also looks good.

So I support these renames, because broken naming only grows to hurt you more and more over time.
