MostHated is looking to replicate an Apache htaccess rule in Nginx that dynamically redirects subdomains to a specific URL path. The rule should take a subdomain (e.g., abc.domain.com) and redirect it to domain.com/forum/c/abc/.
Overgrow suggests running Nginx outside of a Docker container and using a rewrite rule to achieve this. However, MostHated points out that the rule needs to account for dynamic subdomains and found a htaccess to Nginx converter, which helped create a rule.
The proposed rule is:
if ($http_host !~ "^www\."){
rewrite ^(.*)$ http://domain.com/forum/c/%1$1 redirect;
}
However, when combined with the existing proxy pass settings, it creates a loop. Overgrow suggests reading the Nginx manual, and riking recommends seeking help from a more specialized forum.
Overgrow provides additional resources, including DigitalOcean tutorials and Nginx documentation, to help MostHated understand the Nginx configuration file structure and server blocks.
Hey there,
I just switched over to Discourse, I was testing Flarum before with Apache and htaccess and I had a rule written up that whenever there was a subdomain (excluding www.) it would take that subdomain and append it to the end of the url to simulate a dynamic subdomains and I didn’t have to actually make them for them to work how I wanted. Example being if you type “abc.domain.com” it would end up as “domain.com/forum/t/abc” which would drop you in the abc section of the forum. Is it possible to do this with Discourse using nginx?
Looking at how Discourse is laid out, I would want it to be abc.domain.com takes you to domain.com/forum/c/abc/ If anyone has any insight on this, I would appreciate it!
I am already running it externally, I just wasnt sure how to go about that part. Thanks! I will give that a go now.
–
There is more to it isn’t there? Doesn’t a variable have to go at the end of the path based on the subdomain? It will not always be the same. Here is how I had it before.
I mean, you might think that but when I went to test it, it just gave me a loop. In no way does the link you posted explain anywhere near how you would go about merging this:
I am not a server genius / programmer. I just was asking if someone could help. I appreciate you the information, but if I was able to figure it out and get it working, I would not be here asking.
That is fine, I just figured since other people had used the proxy stuff on here before and there were quite a few developers that someone might have some insight.
I have pointed to the tools you need. And there are hundreds of nginx tutorials online. Nothing personal, but if that is not enough, you need to hire admin to do it for you.