Categories on Subdomains.
-
Coming up with thoughts left, right, center and upside down, but running into roadblocks.
If I wanted to have a category attached to a subdomain, what would be the best way to achieve this? I went about this quite heavy handedly, so, I've got a wildcard CNAME in cloudflare that points to my site. I've then set up another nginx config that looks for specific subdomains (I'll use dnb.35hz.co.uk in this case(because it's one I actually set up)), which I want to point at a specific category only.
I thought about just redirecting it, but would rather the domain remain unchanged, so dnb.35hz.co.uk would just show the dnb category. However this adds additional issues when it comes to moving between pages. As the URL is still dnb.35hz, but the actual site is http://35hz.co.uk, so everything 404s.
Is a redirect the realistic only way to do this/am I being over optimistic with my plans?
-
I like it.
-
@julian I was hoping for something that didn't require work. The bigger issue is the routes break, think that's more a core thing. The link in my first post works if you'd like to see what I mean.
I don't mind using redirects, it's possibly easier that way thinking about it.
-
Nice. This is pretty cool.
-
@Ted yeah, any links to things like nodejs.min and the style sheets don't work, because it looks for them on the DNB subdomain. Which technically isn't correct.
-
After some playing about, i've settled on a redirect. If anyone wants to do something similar, create a new file in sites-available called subdomains, then do the usual
sudo ln -s /etc/nginx/sites-available/subdomains /etc/nginx/sites-enabled
Inside the subdomains file, create a server block like thus:
# Mixes server { listen 80; server_name mixes.35hz.co.uk; rewrite ^ $scheme://35hz.co.uk/tags/mix$request_uri? permanent; }
If you want the subdomain to ignore the request parameter, then remove
$request_uri?
portion of the rewrite. This basically means that if someone typedmixes.35hz.co.uk/parameter
it would ignore/parameter
and still go to the relevant tag page without causing a 404. This may be more beneficial. So I'd recommend leaving that portion out. However this would be useful if you wanted a fast way to navigate to a user profile via something likeuser.35hz.co.uk/a_5mith
. Because you could add the request_uri after /user in the rewrite.Just add more server blocks as required for each rewrite. You can stack server_names so that multiple subdomains go to the same link, just add another server_name underneath the existing one.
server_name mixes.35hz.co.uk; server_name mix.35hz.co.uk;