简体   繁体   English

重定向所有带有“ www”前缀的网址,以用于具有子域的应用

[英]Redirect all urls with 'www' prefix for application with subdomains

I am working on a multi-tenant Django application where each tenant gets separate subdomain like tenant1.example.com, tenant2.example.com etc. 我正在开发一个多租户Django应用程序,其中每个租户都获得单独的子域,如tenant1.example.com,tenant2.example.com等。

As far as I know, usually www prefix in url is not used in subdomains. 据我所知,URL中的www前缀通常不在子域中使用。 But I came to know that lot of my users actually add 'www' before any url. 但是我知道很多用户实际上在任何网址之前都添加了“ www”。 Many Tenant1 users enter url as www.tenant1.example.com which means that request doesn't come to actual site. 许多Tenant1用户将URL输入为www.tenant1.example.com,这意味着该请求未到达实际站点。

So, I am thinking of redirecting all the urls which have www prefix to respective subdomain url. 因此,我正在考虑将所有具有www前缀的URL重定向到相应的子域url。 I am not sure what is the best way. 我不确定什么是最好的方法。 I can write a middleware which can do redirect, but I don't feel it's good to do so. 我可以编写一个可以重定向的中间件,但是我觉得这样做不是很好。

I searched but can't find the solution related to subdomain. 我搜索了但找不到与子域相关的解决方案。

I am using Gunicorn, and currently hosting on Heroku. 我正在使用Gunicorn,目前托管在Heroku上。 I can't find any server configuration related to above issue. 我找不到与上述问题相关的任何服务器配置。

How can I solve above issue? 我该如何解决以上问题? I think configuring server would be the best, how do do that if it is possible? 我认为最好配置服务器,如果可能的话该怎么办?

You can do it by nginx or apache settings. 您可以通过nginx或apache设置来做到这一点。 Not on Django itself. 不在Django本身上。

http://www.faultserver.com/q/answers-nginx-forward-all-subdomains-145141.html http://www.faultserver.com/q/answers-nginx-forward-all-subdomains-145141.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM