简体   繁体   English

Django URL重定向问题

[英]Django url redirect issue

I have a view (Let's call it handle_login_redirection ) that handles log-in from a url and redirects to an appropriate url based on the request. 我有一个视图(我们称它为handle_login_redirection ),该视图处理来自URL的登录并根据请求重定向到适当的URL。 This has been working fine. 这一直很好。

Now when I use a custom domain and add the r'^$' pattern to my urlconf so that the Top Level Domain (TLD - www.mysite.com) is redirected to the same view that handles login (ie handle_login_redirection ), I can see that the urls are not rewritten in the browser even when the page is correctly redirected. 现在,当我使用自定义域并将r'^$'模式添加到urlconf以便将顶级域( urlconf )重定向到处理登录的同一视图(即handle_login_redirection )时,请注意,即使页面已正确重定向,URL也不会在浏览器中重写。

Even other urls on the site, while they are directed fine, do not change to their corresponding url path and instead show the TLD in the browser. 即使站点上的其他url都可以正确定向,也不会更改为相应的url路径,而是在浏览器中显示TLD。 Is there anything wrong with the url pattern or is there a better way to handle TLD redirects? 网址格式有什么问题吗?还是有更好的方法来处理TLD重定向?

Also note, I'm deployed to Heroku and there is no Nginx,Apache to configure url rewrites. 另请注意,我已部署到Heroku,并且没有Nginx,Apache用于配置url重写。

So I was doing domain forwarding and masking which was causing the issue. 因此,我正在进行域转发和屏蔽,从而导致了问题。 The right way to do this is to set CNAME entry source to point from your subdomain (www.mysite.com) to mysite.herokuapp.com (for Cedar stack). 正确的方法是将CNAME条目源设置为从您的子域(www.mysite.com)指向mysite.herokuapp.com(对于Cedar堆栈)。 Also had to make entries for A records for naked domains ie mysite.com (Without the www) and point that to mysite.herokuapp.com 还必须为naked domains即mysite.com(不带www)的A records输入条目,并将其指向mysite.herokuapp.com。

And then running heroku domains:add <domain> on both the domain and the sub-domain. 然后运行heroku domains:add <domain>在域和子域上都heroku domains:add <domain>

Helped by How to configure heroku application DNS to Godaddy Domain? 如何将heroku应用程序DNS配置为Godaddy域的帮助? and https://devcenter.heroku.com/articles/custom-domains https://devcenter.heroku.com/articles/custom-domains

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

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