# \`django-hosts\` not routing subdomains correctly, despite correct configurations.

**URL:** https://forum.djangoproject.com/t/django-hosts-not-routing-subdomains-correctly-despite-correct-configurations/42255
**Category:** Mystery Errors
**Created:** [August 6, 2025, 7:01am UTC](https://forum.djangoproject.com/t/django-hosts-not-routing-subdomains-correctly-despite-correct-configurations/42255 "2025-08-06T07:01:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![BlauweStadTechnologi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/blauwestadtechnologi/32/15959_2.png) [@BlauweStadTechnologi](https://forum.djangoproject.com/u/BlauweStadTechnologi)
#### Post date: [August 6, 2025, 7:01am UTC](https://forum.djangoproject.com/t/django-hosts-not-routing-subdomains-correctly-despite-correct-configurations/42255/1 "2025-08-06T07:01:25Z")

</div>

I am really getting to the end of my tether with `django-hosts`

I want to redirect [cerulix.com/blog](http://cerulix.com/blog) → [blog.cerulix.com](http://blog.cerulix.com). But apparently that’s way too much of an ask.

**Here’s my MRE:**

I install the `django-hosts` module in my `.venv` by running the following command:

`pip install django-hosts`

```auto
#settings.py

MIDDLEWARE = [
    'django_hosts.middleware.HostsRequestMiddleware',
    'django_hosts.middleware.HostsResponseMiddleware',
]

INSTALLED_APPS = [
    'blog',
    'django_hosts'
]

ALLOWED_HOSTS = [
    '127.0.0.1', 
    'cerulix.com', 
    'www.cerulix.com',
    'blog.cerulix.com',
]

ROOT_HOSTCONF = "cerulix.hosts"
DEFAULT_HOST = "www"
PARENT_HOST = 'cerulix.com'

```

```auto
#cerulix.hosts

from django_hosts import patterns, host
from django.conf import settings
from django.urls import path, include

host_patterns = patterns('',
                         
    host(r'www', settings.ROOT_URLCONF, name='www'),
    host(r'blog', 'blog.urls', name='blog')

)

```

```auto
#cerulix.urls

from . import views
from django.conf import settings
from django.conf.urls.static import static
from django.views.static import serve

urlpatterns = [
    path('', views.index),
    path('blog', include('blog.urls'), name='blog'),

]

```

```auto
#blog.urls
from django.urls import path
from. import views

urlpatterns = [

    path('', views.blog, name='blog'),
    path('<slug:slug>', views.blog__details),

]

```

```auto
#index.html
{% load hosts %}

<a href="{% host_url 'blog' host 'blog' %}" >Blog</a></li>

```

As you can see, everything is set up correctly.

Guess what?

- You type `blog.<domain>.com` into the URL, → `index.html`
- You go to the `blog` `<a href=">` link, it does go to the blog, but the URL in the address bar is `blog.cerulix.com/blog`. How absolutely stupid can this thing be?
- You then click off of the blog to go to another page, guess what, the address in the URL bar is - yup, you guessed it -`blog.cerulix.com`

So why? My configurations are correct, so why?

You have zero idea how sick to the back teeth I am of this.

---

<div class="post-metadata">

### Author: ![philgyford](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/philgyford/32/14295_2.png) [@philgyford](https://forum.djangoproject.com/u/philgyford)
#### Post date: [August 6, 2025, 7:53am UTC](https://forum.djangoproject.com/t/django-hosts-not-routing-subdomains-correctly-despite-correct-configurations/42255/2 "2025-08-06T07:53:52Z")

</div>

> [@BlauweStadTechnologi](#):
>
> I want to convert [cerulix.com/blog](http://cerulix.com/blog) → [blog.cerulix.com](http://blog.cerulix.com).

What do you mean by “convert”? Do you mean redirect? If so, that doesn’t appear to be what django -hosts is for.

It allows you to route requests for different hosts to different urlconf files. That’s it.

> [@BlauweStadTechnologi](#):
>
> You go to the `blog` `<a href=">` link, it does go to the blog, but the URL in the address bar is `blog.cerulix.com/blog`. How absolutely stupid can this thing be?

It’s doing what you’ve told it:

> [@BlauweStadTechnologi](#):
>
> `<a href="{% host_url 'blog' host 'blog' %}" >Blog</a></li>`

You’re generating a link to the “blog” page on the host “blog”. So `blog.cerulix.com/blog`

> [@BlauweStadTechnologi](#):
>
> You then click off of the blog to go to another page, guess what, the address in the URL bar is - yup, you guessed it -`blog.cerulix.com`

Are the links you’re clicking generated using the `host_url` tag? If so, which host are they generating links for?

---

<div class="post-metadata">

### Author: ![BlauweStadTechnologi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/blauwestadtechnologi/32/15959_2.png) [@BlauweStadTechnologi](https://forum.djangoproject.com/u/BlauweStadTechnologi)
#### Post date: [August 6, 2025, 8:23am UTC](https://forum.djangoproject.com/t/django-hosts-not-routing-subdomains-correctly-despite-correct-configurations/42255/3 "2025-08-06T08:23:48Z")

</div>

Yup, by “convert" I mean, redirect. I will reword.

> It allows you to route requests for different hosts to different urlconf files. That’s it.

That’s exactly what `django-hosts` are used for.

It says in the official documentation, & it’s not doing what I have told it to do, I have told it go to the blog section & display `blog.cerulix.com` in the URL bar in the browser, just like every other website in the world that uses subdomains.

The other links I am clicking on AFTER I have visited the blog page, which django clearly seems to have an identity crisis over, are not hosted by the `host_url` tag - because they are hosted by the `urls` tag. It’s how it worked before `django-hosts` because the insanity of my life and now the browser is having a hissy fit over it.

Is this thing a django module or a baby?

Just every little thing, there’s an issue with it. Issue after error after issue after error after issue. I am so sick and tired of it. Why can’t something just do what I tell it to without arguing with me? Why do I have to waste my time, scream, rip my hair out just because this module decides when it is going to do as it’d told?

---

<div class="post-metadata">

### Author: ![philgyford](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/philgyford/32/14295_2.png) [@philgyford](https://forum.djangoproject.com/u/philgyford)
#### Post date: [August 6, 2025, 8:36am UTC](https://forum.djangoproject.com/t/django-hosts-not-routing-subdomains-correctly-despite-correct-configurations/42255/4 "2025-08-06T08:36:41Z")

</div>

> [@BlauweStadTechnologi](#):
>
> Yup, by “convert" I mean, redirect. I will reword.

Then django-hosts is not what you need. It doesn’t redirect a request for one URL to another URL. It routes requests to urlconf files (and so URLs) based on the domain name. Without redirecting the browser to a new URL.

> [@BlauweStadTechnologi](#):
>
> Yup, by “convert" I mean, redirect. I will reword.

It’s doing exactly what you have told it to do.

> [@BlauweStadTechnologi](#):
>
> I have told it go to the blog section & display `blog.cerulix.com` in the URL bar in the browser, just like every other website in the world that uses subdomains.

django-hosts does not change what is in the URL bar in the browser. It looks at what is in the URL bar and serves a view depending on which domain is in that URL bar. That’s it.

> [@BlauweStadTechnologi](#):
>
> The other links I am clicking on AFTER I have visited the blog page, which django clearly seems to have an identity crisis over, are not hosted by the `host_url` tag - because they are hosted by the `urls` tag.

So, if you look at the source of the page in your browser, you’ll see that those links are like `/blog/foo/`. i.e. they do not have `https://<domain>` at the start. Therefore they will go to that URL on the same domain as the current page. If you want them to go to a different domain, you’ll have to use the `host_url` tag.

> [@BlauweStadTechnologi](#):
>
> The other links I am clicking on AFTER I have visited the blog page, which django clearly seems to have an identity crisis over, are not hosted by the `host_url` tag - because they are hosted by the `urls` tag.

You need to take a step back, understand how browsers, URLs and redirections work, understand the documentation for the tools you’re using, and quit blaming everything else for things not working when you haven’t set them up properly, or are using the wrong tools.

---

<div class="post-metadata">

### Author: ![philgyford](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/philgyford/32/14295_2.png) [@philgyford](https://forum.djangoproject.com/u/philgyford)
#### Post date: [August 6, 2025, 10:12am UTC](https://forum.djangoproject.com/t/django-hosts-not-routing-subdomains-correctly-despite-correct-configurations/42255/6 "2025-08-06T10:12:00Z")

</div>

You’ve “told it” to do something it wasn’t designed to do.
