# Recent Changes Breaking Subfolder Setup?

**URL:** https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232
**Category:** Bug
**Created:** [February 10, 2020, 11:02pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232 "2020-02-10T23:02:44Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![hartz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hartz/32/167110_2.png) [@hartz](https://meta.discourse.org/u/hartz)
#### Post date: [February 10, 2020, 11:02pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/1 "2020-02-10T23:02:44Z")

</div>

I’m sorry if I’ve misdiagnosed this, but I’ve recently experienced some issues after an upgrade on a subfolder setup that had been working before, so I think there may have been a regression on some fronts in the recent past? In particular, I am self-hosting Discourse using the subfolder setup described [here](https://meta.discourse.org/t/subfolder-support-with-docker/30507), which was happily working (AFAICT) until recently.

Currently, when logging in using SSO or when switching to/from anonymous mode (and maybe in other situations I’ve not yet found), I am redirected to `https://my_machine/discourse_path_stuff` , rather than being redirected to `https://my_machine/forum/discourse_path_stuff`. It’s also the case that when I go to `https://my_machine/forum` (the right endpoint), my address bar is rewritten to say `https://my_machine` (with the subfolder removed), though most links seem to resolve to the right places.

Unfortunately, I don’t remember what commit I was running on when things were working, but I’m pretty sure it was under the “2.4.0.beta10” umbrella, and was probably within the last ~10 days. I am currently running on `bd49d4af1a`.

I apologize if I’m just doing something stupid, and I’m happy to help with tracking down the issue if there are suggestions for where I should be looking.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [February 10, 2020, 11:58pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/2 "2020-02-10T23:58:15Z")

</div>

Can you share the site URL ? Are you using our SSO protocol or some OAuth2 / omniauth strategy?

---

<div class="post-metadata">

### Author: ![hartz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hartz/32/167110_2.png) [@hartz](https://meta.discourse.org/u/hartz)
#### Post date: [February 11, 2020, 12:16am UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/3 "2020-02-11T00:16:04Z")

</div>

Sure, it’s at [https://py.mit.edu/forum](https://py.mit.edu/forum) (but that’s currently locked off from public viewing). [https://py.mit.edu/forum/login](https://py.mit.edu/forum/login) demonstrates the problem (though I put another NGINX rule in place specifically to 302 [https://py.mit.edu/login](https://py.mit.edu/login) back to [https://py.mit.edu/forum/login](https://py.mit.edu/forum/login) once we started seeing this, which has been a workaround for the SSO part, at least).

We’re using the [Discourse SSO](https://meta.discourse.org/t/13045?silent=true) protocol, which was definitely working smoothly before. The handshake still seems to happen fine, just redirecting to the wrong place at the end. The `"return_sso_url"` key in the SSO payload is coming back to our SSO endpoint correctly, though (with `/forum`).

I also tried a rebuild, but that didn’t seem to fix the issue.

Unfortunately, this may be difficult to debug since I’m not really comfortable giving outside people access, since this instance exists for a class, and I don’t feel comfortable sharing student data with outside parties (even if I trust you personally!). But if it helps, I’m happy to try to replicate this setup on a different server that I could give you access to…

---

<div class="post-metadata">

### Author: ![hartz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hartz/32/167110_2.png) [@hartz](https://meta.discourse.org/u/hartz)
#### Post date: [February 11, 2020, 12:28am UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/4 "2020-02-11T00:28:53Z")

</div>

I also see that the link for entering/leaving anonymous mode is using the `window.location.reload()` to reload the page after sending a request to an endpoint to switch to anonymous mode. So that reload would definitely see the rewritten URL (no longer containing `/forum`), which would cause this (not sure if it’s a similar story for the SSO problems).

I’ll take a peek at the recent changesets to see if the thing that (I think?) is rewriting `window.location` is a recent addition.

Also, `Discourse.getURL('/login')` still gives me the right result (with `/forum`).

---

<div class="post-metadata">

### Author: ![bokos](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@bokos](https://meta.discourse.org/u/bokos)
#### Post date: [February 10, 2020, 6:18pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/8 "2020-02-10T18:18:38Z")

</div>

The paths reset without subfolder prefix in the address bar of the browser.

Example:  
I visit [example.com/forum](http://example.com/forum) → after forum loaded, address bar shows [example.com](http://example.com)  
Then I click on “Latest” → navigates to latest and address bar shows [example.com/forum/latest](http://example.com/forum/latest)  
I hit refresh on browser, website refreshes and address bar shows [example.com/latest](http://example.com/latest)  
When I refresh again while on [example.com/latest](http://example.com/latest), there is a 404 error (because my nginx only routes /forum to discourse).

The link preview at bottom left of the browser show up as [example.com/latest](http://example.com/latest), [example.com/new](http://example.com/new) etc. Refreshing a topic also removes /forum from the url, but then it changes again, back to /forum/t/[…].

I was at version 2.4.0.beta2 previously and don’t remember this issue.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [February 10, 2020, 7:12pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/9 "2020-02-10T19:12:13Z")

</div>

Was this install created following [Subfolder support with Docker](https://meta.discourse.org/t/subfolder-support-with-docker/30507) ? Can you link to it?

---

<div class="post-metadata">

### Author: ![bokos](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@bokos](https://meta.discourse.org/u/bokos)
#### Post date: [February 11, 2020, 5:23pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/10 "2020-02-11T17:23:25Z")

</div>

Yes, I also tried it on a fresh local install and got the same issue:

app.yml

```plaintext
templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"

expose:
 - 80:80

params:
  db_default_text_search_config: "pg_catalog.english"
  version: tests-passed

env:
  LANG: en_US.UTF-8
  UNICORN_WORKERS: 3
  DISCOURSE_RELATIVE_URL_ROOT: /forum
  DISCOURSE_HOSTNAME: localhost
  DISCOURSE_DEVELOPER_EMAILS: yyy

  DISCOURSE_SMTP_ADDRESS: yyy
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: yyy@yyy.yyy
  DISCOURSE_SMTP_PASSWORD: yyy
  DISCOURSE_SMTP_AUTHENTICATION: login

volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
            - git clone https://github.com/discourse/docker_manager.git

run:
    - exec:
        cd: $home
        cmd:
          - mkdir -p public/forum
          - cd public/forum && ln -s ../uploads && ln -s ../backups
    - replace:
       global: true
       filename: /etc/nginx/conf.d/discourse.conf
       from: proxy_pass http://discourse;
       to: |
          rewrite ^/(.*)$ /forum/$1 break;
          proxy_pass http://discourse;
    - replace:
       filename: /etc/nginx/conf.d/discourse.conf
       from: etag off;
       to: |
          etag off;
          location /forum {
             rewrite ^/forum/?(.*)$ /$1;
          }

```

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [February 11, 2020, 7:27pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/11 "2020-02-11T19:27:05Z")

</div>

I can reproduce the issue on my subfolder install. We’ll get this fixed.

---

<div class="post-metadata">

### Author: ![hartz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hartz/32/167110_2.png) [@hartz](https://meta.discourse.org/u/hartz)
#### Post date: [February 11, 2020, 7:32pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/12 "2020-02-11T19:32:34Z")

</div>

Great, thanks! Glad to know that I’m not crazy.

From poking around in the recent(ish) commits, though, I couldn’t see an obvious point where this rewrite was happening. Would it be possible to get a pointer to where in the code this was/is happening? (I’m in the process of trying to familiarize myself with the codebase).

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [February 11, 2020, 7:35pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/13 "2020-02-11T19:35:44Z")

</div>

> [@hartz](#):
>
> Would it be possible to get a pointer to where in the code this was/is happening?

It would be! I’m just not your guy. I’m just “that guy” on the team that happens to have a local subfolder install. But I’m not an engineer. David should be able to point you in the right direction when he starts working on the issue later this week.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [February 11, 2020, 8:44pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/14 "2020-02-11T20:44:48Z")

</div>

> [@hartz](#):
>
> where in the code

Almost certainly [this change](https://github.com/discourse/discourse/commit/fe0d912b97985a6272e720729aa6197e8e40274f) which was for [this issue](https://meta.discourse.org/t/discourse-docker-blocked-csp-error-with-svg-sprite-when-using-subfolders/139492/9). I’m not sure exactly what the issue is, but I’ll be looking into it :eyes:

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [February 11, 2020, 11:08pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/15 "2020-02-11T23:08:26Z")

</div>

Turns out it was completely unrelated to that commit. I’ve found the source of the issue, and a fix is in the pipeline:

[https://github.com/discourse/discourse/pull/8932](https://github.com/discourse/discourse/pull/8932)

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [February 11, 2020, 11:11pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/16 "2020-02-11T23:11:46Z")

</div>

Excellent detective :man_detective: work @david :clap:

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [February 12, 2020, 10:04am UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/17 "2020-02-12T10:04:23Z")

</div>

This is now merged - @hartz and @bokos can you confirm that the issue is resolved after an update?

---

<div class="post-metadata">

### Author: ![hartz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hartz/32/167110_2.png) [@hartz](https://meta.discourse.org/u/hartz)
#### Post date: [February 12, 2020, 11:01am UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/18 "2020-02-12T11:01:15Z")

</div>

After a little bit of testing, things do indeed seem to be working again. Thanks, @david !

---

<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: [February 12, 2020, 5:13pm UTC](https://meta.discourse.org/t/recent-changes-breaking-subfolder-setup/141232/19 "2020-02-12T17:13:18Z")

</div>


