Django/Heroku hide heroku url by subdomains name - django

I'm currently deploying some django app on Heroku.
I bought a domain name on Gandi, and made a subdomain redirecting (temporary redirection) on my heroku server. Currently, the subdomain is redirecting to the machine, this is working.
mysubdomain.mydomain.com --> something.heroku.com
However, when I navigate throught my website, I still have on my address bar the heroku domain name in front of my page (something.heroku.com/detailpage/slugforexample)
I would like to hide the heroku domain name by my subdomain name (to have something like subdomain.domain.com/detailpage/slugforexample)
I set the Gandi configuration (temporary redirection to heroku server)
I set on heroku domains:add with my subdomain.
Where do I have to configure the redirection ? Is it in heroku, wsgi, django conf ?

You shouldn't use Web Forwarding to achieve what you want. You should add a CNAME entry on GANDI for mysubdomain on your mydomain.com domain with a value of something.heroku.com. You should then add a custom domain to your application via heroku domains:add mysubdomain.mydomain.com - it looks like you've already done this last bit.
This means you will be able to navigate to mysubdomain.mydomain.com and the address bar will rename as this.

Related

What is the correct way to do a redirection from www. to the naked domain (Server or App or Domain Provider)?

I currently have an app that works with both www.domain.com and domain.com. Considering that this seems to be bad for SEO, I want it to always redirect to the naked domain.
My app works in this way:
Server: Google Cloud Platform (App engine)
App: Django
Domain provider: Godaddy
As I have researched the redirection can be done from any of these 3 options. So I want to ask: What is the best option and why?
I tested to do the redirection with GoDaddy on App Engine (An A record for www pointing to #) but when I set my custom domain in App Engine, I noticed that for the www.domain a C Record pointed to ghs.googlehosted.com setting was required in the app engine panel, I omitted that in order to do the redirection in GoDaddy, but the app wouldn't load when visiting from www.domain, a 404 error appeared (Also tried by omitting the addition of the www.domain altogether in app engine settings) So I wasn't able to accomplish this in the same fashion than an app that is hosted in a single server.
I think the easiest way would be to handle this inside the app itself like this site mentions

Redirect domain to .com in django in url.py

I have a website in Django, hosted in Heroku.
I have 2 domains, registered in different places:
mysite.com and mysite.com.br
I don't want to be penalized by Google for having 2 domains with the same website, therefor I would like to redirect everyone who enters mysite.com.br to mysite.com.
I entered in the DNS mysite.com.br(Not hosted anywhere) CNAME mysite.com(hosted in Heroku), which makes the user actually access the Heroku content, but the url keeps the .BR ....
So the Heroku support told me to do the redirection in the application. In this case, what's the best practice to redirect? I would imagine to do that in the url.py, but how can I do that if the "path" doesnt read the domain?
Thanks.
You can't do this in the URLs. I would write some middleware to check the host via request.get_host and redirect if you're not on the canonical one.
In fact it looks like someone has already written this: django-enforce-host.

Django: Multiple Logins

I have just deployed my django project on dogitalocean (nginx/ubuntu 16.04) server.
In Allowed hosts I added ['.example.com', 'IP']
In the DNS records of my digitalocean droplet I added two A type records one is pointing example.com to the IP, & the second is pointing www.example.com to the same IP.
Problem is that I visited the site as example.com & logged in as a normal user, & then I opened a new tab (still logged in at example.com) & visited site using www as www.example.com & i'm not logged in there.
How can I redirect example.com to www.example.com? Thank You :)
Your session cookie is not valid for both domains, that's why you're not logged in when accessing www.example.com.
One way to fix it is to set
SESSION_COOKIE_DOMAIN=".example.com"
in settings.py so the session cookie is valid for example.com and all subdomains.
(note the . preceding the domain name)
See the Django session settings documentation for more information.

how to copy url without "www" to the url with "www"?

I'm hosting a Django project, let's say the name is www.example.com, when an user search for example.com/subname to redirect to www.example.com/subname. Unfortunalety, right now it's redirecting to www.example.com without adding the "subname" part to my url.
I have my domain name on infomaniak which redirects example.com to www.example.com, the hosting is on pythonanywhere where it handles my Django project.
How can I achieve the case where what's put after domain name url is kept and used to redirect to the one with www. ?
(For my Django project I'm not using apache nor nginx, so where is the htaccess file if the changes has to be made there ?)
UPDATE for Udlei Nati's answer :
UPDATE 2 : for Astik Anand : This is where the actual redirection is made. (site.com redirect to another site which was the old version of the one on www. (that's why I'm trying to override it.))

I hosted Opencart on openshift, But after CNAME mapping, Application is showing 404 Error

I have successfully deployed opencart on openshift, and It is running properly with the url provided by the openshift, But when I have mapped that URL with the CNAME in my domain name, It is showing Error that App is not found.
Can someone please help me for the same.
You may need to set your alias to the domain name you have chosen. You can do this via the web console. Aliases are what allow you to use your own domain names for your applications on OpenShift.
It's a 2 step process
(1) Set up the CNAME record with your DNS provider
it sounds like you have already done this at your DNS provider
(2) Configure OpenShift to use your alias
so from the web console, go to your application's main page by clicking on Settings icon then click on "Change" link to enter your custom domain name e.g. www.example.com or something.example.com.
Let us know if that works,
Diane