# How to run discourse on subdirectory of external domain?

**URL:** https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788
**Category:** Self-hosting
**Tags:** unsupported-install
**Created:** [December 1, 2019, 8:15am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788 "2019-12-01T08:15:08Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![UltraLuz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ultraluz/32/160013_2.png) [@UltraLuz](https://meta.discourse.org/u/UltraLuz)
#### Post date: [December 1, 2019, 8:15am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/1 "2019-12-01T08:15:09Z")

</div>

We are moving away from our wordpress website to a cloud hosted e-commerce platform, which will use our bare domain due to our high SEO ranking.

I want to move our posts to discourse, but run it under the same domain is that possible?

To be clear, [http://ultraluz.com.br/](http://ultraluz.com.br/) will be running in a external server I can’t control or access so I believe I can’t use nginx tricks or something. I only have access to the server that will be running discourse.

My goal is to move posts like this [http://ultraluz.com.br/iluminacao-para-esportes-como-deixar-as-instalacoes-esportivas-dignas-de-um-atleta-profissional/](http://ultraluz.com.br/iluminacao-para-esportes-como-deixar-as-instalacoes-esportivas-dignas-de-um-atleta-profissional/) to discourse but keep same path or at best `domain/blog/same-url` while my bare domain is pointed and hosted in a Wix-like platform.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 1, 2019, 11:08am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/2 "2019-12-01T11:08:28Z")

</div>

It might be possible to have cloudflare in front of both sites with a rule to route traffic to discourse for the subfolder. I am not aware of anyone doing that. You’ll probably need to hire someone or figure out out on your own. Just follow the topic here about subfolder installs and whatever cloudflare has about the same.

I thought that the belief that a subfolder was better for seo had gone away. My recommendation would be to just use a subdomain, but if you have a budget contact me or post in #Marketplace.

---

<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: [December 1, 2019, 12:57pm UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/3 "2019-12-01T12:57:06Z")

</div>

You could _technically_ achieve the subfolder part at Cloudflare using an Enterprise page rule or maybe via workers but I’m pretty skeptical that we could provide any assistance with either.

Cloudflare is hard to support in any form beyond DNS.

And yes, Google themselves have debunked the whole SEO snake oil around cramming everything under a single domain.

---

<div class="post-metadata">

### Author: ![UltraLuz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ultraluz/32/160013_2.png) [@UltraLuz](https://meta.discourse.org/u/UltraLuz)
#### Post date: [December 1, 2019, 8:26pm UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/4 "2019-12-01T20:26:42Z")

</div>

Better safe than sorry with SEO. I don’t see how a blog.domain would boost my domain seo, so there is no point in having a blog domain at all.

> **[SEO Best Practices with Cloudflare Workers, Part 2: Implementing Subdomains](https://blog.cloudflare.com/subdomains-vs-subdirectories-improved-seo-part-2/)**
>
> Subdomains and subdirectories are different strategies for instrumenting root domains with new features, but which strategy is technically better?

I’ve been thinking in following this guide. Which ` assetsPathnames: ["/public/", "/assets/"] ` I should use?

---

<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: [December 1, 2019, 8:45pm UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/5 "2019-12-01T20:45:04Z")

</div>

Subfolder installs are much more complicated and very fragile.

The point is that there’s zero benefit running under the same FQDN and significantly more risk and cost.

---

<div class="post-metadata">

### Author: ![UltraLuz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ultraluz/32/160013_2.png) [@UltraLuz](https://meta.discourse.org/u/UltraLuz)
#### Post date: [December 1, 2019, 8:48pm UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/6 "2019-12-01T20:48:46Z")

</div>

That’s what you believe. But there is no evidence that a subdomain helps boost the bare domain at all.

And even cloudflare recommends running everything in the same domain.

---

<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: [December 1, 2019, 8:55pm UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/7 "2019-12-01T20:55:17Z")

</div>

Then why, pray tell, is their discourse community on a subdomain?

---

<div class="post-metadata">

### Author: ![UltraLuz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ultraluz/32/160013_2.png) [@UltraLuz](https://meta.discourse.org/u/UltraLuz)
#### Post date: [December 1, 2019, 8:56pm UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/8 "2019-12-01T20:56:01Z")

</div>

Because anything with cloudflare in the domain will rank well. And their forum is enormous

---

<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: [December 1, 2019, 10:15pm UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/9 "2019-12-01T22:15:36Z")

</div>

If that’s what you believe, move along. There is nothing for you here. Go elsewhere, go somewhere that people believe the same things you do.

---

<div class="post-metadata">

### Author: ![UltraLuz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ultraluz/32/160013_2.png) [@UltraLuz](https://meta.discourse.org/u/UltraLuz)
#### Post date: [December 2, 2019, 3:50am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/10 "2019-12-02T03:50:45Z")

</div>

> **[Subdirectories vs. Subdomains for 2019 and Beyond](https://portent.com/blog/seo/subdirectories-vs-subdomains.htm)**
>
> What's best for rankings, a subdomain or a subdirectory? SEOs and Google can't agree, but there's a strong case for one of them.

> **[Subdomains vs. Subfolders: Which Is Better for SEO & Why?](https://www.searchenginejournal.com/subdomains-vs-subfolders-seo/239795/)**
>
> The use of a subdomain or a subfolder has SEO, user experience, and other implications. Learn about the pros, cons, and use cases of each one.

I could link much more links, with data behind them if I wasn’t limited to 2 links. And except for Cloudflare, which is massive and don’t need to focus on SEO all websites on the first page for this search use subdirectories

It won’t be hard to find other places where people believe the same thing since this seems to be consensus on the SEO community.

But sure, if you have ANY evidence that a subdomain helps rank the root domain please enlighten the internet 🙂

---

<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: [December 2, 2019, 4:03am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/11 "2019-12-02T04:03:18Z")

</div>

Direct from Matt Cutts. Your SEO “experts” are selling you snake oil.

> [@Blog on subfolder in discourse](https://meta.discourse.org/t/blog-on-subfolder-in-discourse/32883/10):
>
> Here is a response from Matt Cutts in email to me: pretty much everyone who has strong opinions on subdomains vs. subfolders doesn’t know what they’re talking about. They sure do have strong opinions anyway though! Sorry, I believe Matt Cutts of Google over your random link wink

Through the years some of the worst, least competent people I’ve _ever_ seen on a team are the “SEO experts”. They are uniformly a disgrace and an embarrassment to the industry.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 2, 2019, 5:01am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/12 "2019-12-02T05:01:26Z")

</div>

> [@UltraLuz](#):
>
> Better safe than sorry with SEO.

True! Tons better to do something that most everyone agrees won’t help web rankings but will likely result in your site being down unexpectedly with no clear means to fix it.

---

<div class="post-metadata">

### Author: ![UltraLuz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ultraluz/32/160013_2.png) [@UltraLuz](https://meta.discourse.org/u/UltraLuz)
#### Post date: [December 2, 2019, 3:40am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/13 "2019-12-02T03:40:13Z")

</div>

Anyone have tried to do this with cloudflare?

---

<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: [December 2, 2019, 6:00am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/14 "2019-12-02T06:00:11Z")

</div>

As we’ve already explained in your other topic, what you’re asking to do can’t be supported here.

You will either need an Enterprise plan with Cloudflare, or to create custom workers. Either way you should be talking to Cloudflare.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 2, 2019, 7:51am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/15 "2019-12-02T07:51:52Z")

</div>

As stated, [the answer that I gave earlier](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/2), is all you’ll get here.

What I didn’t make clear enough is that it’s a fool’s errand.

For a frame of reference, I’d charge you on the order of $1000 and provide no promise that it would work for for more than a week after I set it up. (or I might charge $500 with no promise that I could figure it out at all.

And you’d need the cloudflare enterprise plan.

If you’re interested, post in #Marketplace and include a budget and that you are willing to pay for cloudflare enterprise and understand that it is likely impossible.

---

<div class="post-metadata">

### Author: ![UltraLuz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ultraluz/32/160013_2.png) [@UltraLuz](https://meta.discourse.org/u/UltraLuz)
#### Post date: [December 2, 2019, 8:59am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/16 "2019-12-02T08:59:36Z")

</div>

I think I’m 80% done in implementing this. I installed discourse on a subdomain as “normal” install.

Then I created a cloudflare worker proxying `/blog` to my subdomain. It works but chrome refuses to load some stuff because of CSP policy.

Any ideas to go around this anyone? I’ll share my workers code when it’s 100%.

You can go to [https://ultraluz.com.br/blog](https://ultraluz.com.br/blog) to check what is happening.

 ![image](https://global.discourse-cdn.com/meta/original/3X/f/3/f3e6661ab09bb67e2f1724eb2dffdd4135047367.png)

My idea is that after I fix this, I’ll just use robots.txt to block google from indexing my subdomain, so it only sees and indexes `/blog` while I can still access the subdomain just fine if needed

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [December 2, 2019, 9:11am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/17 "2019-12-02T09:11:30Z")

</div>

> [@UltraLuz](#):
>
> I installed discourse on a subdomain as “normal” install.
> 
> It works but chrome refuses to load some stuff because of CSP policy.

This is never going to work really well with a “normal” install, you really should follow [the subfolder install procedure](https://meta.discourse.org/t/subfolder-support-with-docker/30507). It will fix your CSP issues and many more. Apart from that, I think you’re almost there.

---

<div class="post-metadata">

### Author: ![UltraLuz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ultraluz/32/160013_2.png) [@UltraLuz](https://meta.discourse.org/u/UltraLuz)
#### Post date: [December 2, 2019, 9:19am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/18 "2019-12-02T09:19:16Z")

</div>

What I should set `DISCOURSE_HOSTNAME` when using `DISCOURSE_RELATIVE_URL_ROOT` ? The relative root will be blog for me right?

How does this change stuff related to SSL? This is my env section of yml

```
env:
  LANG: en_US.UTF-8
  DISCOURSE_RELATIVE_URL_ROOT: /forum

  VIRTUAL_HOST: forum.ultraluz.com.br
  VIRTUAL_PORT: 80
  LETSENCRYPT_HOST: forum.ultraluz.com.br
  LETSENCRYPT_EMAIL: redacted@email.com

  DISCOURSE_HOSTNAME: forum.ultraluz.com.br
  DISCOURSE_DEVELOPER_EMAILS: 'redacted@email.com'

  DISCOURSE_SMTP_ADDRESS: smtp.sendgrid.net
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: apikey
  DISCOURSE_SMTP_PASSWORD: "password"
  DISCOURSE_SMTP_ENABLE_START_TLS: true
  SSL_POLICY: Mozilla-Modern  

```

The letsencrypt and virtual host stuff is for my nginx docker (jwilder/nginx-proxy) that handles the proxying and ssl creation for me based on that variables…

Also had this but I think it will be fully replaced by the code there?

```
run:
  - replace:
      filename: /etc/nginx/conf.d/discourse.conf
      from: "types {"
      to: |
        set_real_ip_from 172.18.0.0/24;
        real_ip_header X-Forwarded-For;
        real_ip_recursive on;
        types {

```

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [December 2, 2019, 9:47am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/19 "2019-12-02T09:47:13Z")

</div>

> [@UltraLuz](#):
>
> The relative root will be blog for me right?

Yes, `/blog` including the slash.

> [@UltraLuz](#):
>
> `DISCOURSE_HOSTNAME: forum.ultraluz.com.br`

No, just `ultraluz.com.br`.

I guess you should leave the LetsEncrypt part as it is.

---

<div class="post-metadata">

### Author: ![UltraLuz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ultraluz/32/160013_2.png) [@UltraLuz](https://meta.discourse.org/u/UltraLuz)
#### Post date: [December 2, 2019, 10:10am UTC](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788/20 "2019-12-02T10:10:56Z")

</div>

It didn’t work this way. I guess it’s because the worker needs a domain to fetch stuff, and since the root domain is on a different IP.

I’m basically telling the worker “when someone goes to `/blog` fetch this from `rootdomain/blog`” this of course just displays my current wordpress 404 error page.

I think because of the whole same domain, multiple IPs/servers things a subdomain is needed to load the discourse assets. But it’s late now and I need to sleep.

But I think the easiest way to achieve this will be to just fix the CSP errors with usual subdomain install.

[Next page](https://meta.discourse.org/t/how-to-run-discourse-on-subdirectory-of-external-domain/134788.md?page=2)
