I'm using the Mezzanine Django-based CMS using its Multi-Tenancy ability to serve two sites through the same backend, and have a quirk occurring with respect to the "www" subdomain from one of the sites. At the moment, this is how it's working:
site_1.com -> site_1
www.site_1.com -> site_1
site_2.com -> site_2
www.site_2.com -> site_1
As you can see, the "www" subdomain is going to the wrong site. The HOST_THEMES setting seems to be set correctly, however - like so:
HOST_THEMES = [('www.site_1.com', 'site_1_theme'),
('site_1.com', 'site_1_theme'),
('www.site_2.com', 'site_2_theme'),
('site_2.com', 'site_2_theme')]
Additionally, Admin>Settings>Sites is set like so:
site_1.com
site_2.com
(No "www"s are listed, since adding one would add a completely separate site in the admin for content). What is the proper way to handle www subdomains here? Why would it properly handle the raw domain, yet not the www?
Thank you.
Redirect the www sites to the non-www sites (or vice-versa), in your nginx/apache conf.
Related
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.
Let's assume I own the domain:
foobar.com/
I want to use Netlify for my static pages like
foobar.com/features/
foobar.com/pricing/
foobar.com/imprint/
etc.
But I also have a Django application on a seperate server on AWS that has nothing to do with the static sites served by Netlify.
My Django has urls like
foobar.com/login/
foobar.com/dashboard/
etc.
Is it possible to use Netlify for a few static pages and my Django application for other pages?
I don't know how start or if this is event possible.
It will depend on how your Django apps handle the target, but you could use rewrites on Netlify using the HTTP status code 200 with a redirect rule (rewrite).
If the API supports standard HTTP caching mechanisms like Etags or Last-Modified headers, the responses will even get cached by CDN nodes.
Have DNS set foobar.com to the Netlify site.
Decide the domain for the Django site on AWS. (proxy.foobar.com)
Setup _redirects at the root of the Netlify site to use Proxy (rewrites) on Netlify
/login/* https://proxy.foobar.com/login/:splat 200
/dashboard/* https://proxy.foobar.com/dashboard/:splat 200
Note: This is how you can incrementally switch a site over to Netlify without having to refactor a site all at once.
When you set a DNS record (e.g. an A record), you can point foobar.com to your AWS server or netlify, but not both.
Perhaps you can put the sites on different domains, for example dashboard.foobar.com for your Django site.
You could then configure netlify to redirect foobar.com/dashboard/ to dashboard.foobar.com/dashboard/
No, you can't have a foobar.com point to two different servers. You'll have to use subdomains, e.g.:
static.foobar.com -> DNS entry for Netlify
app.foobar.com -> DNS entry for your Django server
or, what you often see, is:
foobar.com and www.foobar.com -> DNS pointing to your main website (Netlify)
api.foobar.com and app.foobar.com -> DNS pointing to your Django app
I need to clarify a fundamental concept (beginner here).
In a Django web app I maintain, I notice that if one logs in via going to example.com, they remain logged out on www.example.com (and can then go on to create a clone account).
1) Why does this happen?
2) What's the standard practice to iron out this issue? I.e., give one consistent experience across www and no-www.
In case the answer is as basic as just a redirection, I could use some pointers and an illustrative example there too - I'm using nginx reverse proxy with gunicorn.
1 ) Django cookies do not work for same with a prepended www and non-www domain by default.Django considers it as a different sessions.
2) The PREPEND_WWW setting you can set to redirect your xyz.com to www.xyz.com.
PREPEND_WWW = True
or if you need same cookie to both of the sites you can use session_cookie_domain,
SESSION_COOKIE_DOMAIN = ".yoursite.com"
I'm trying to set a cookieless subdomain to serve static content of my wordpress website. So I've tried self-hosted CDN solutions using WP SuperCache or W3 Total Cache plugin.
My wordpress is on the domain aljazair24.com and my CDN domain is static1.aljazair24.com. The domain and subdomain point to the same apache directory (/home/username/public_html).
Although WP SuperCache and W3TC plugins allow to set cookie domain to aljazair24.com, the subdomain static1.aljazair24.com still sends cookies to browsers...
I've tried to set cookie domain to www.aljazair24.com in order to avoid this but it doesn't work, since all www urls are redirected to non-www ones...
I was desperately looking for any WP plugin allowing to make "real" mirror resources, all this in order to avoid any interference at htaccess level. Unfortunately I didn't find anything ...
What should I do to make subdomain static1.aljazair24.com cookie-free ?
Page speed tests using YSlow
Grade F on Use cookie-free domains
There are 82 components that are not cookie-free
http://static1.aljazair24.com/wp-content/plugins/ajax-load-more/core/js/ajax-load-more.min.js
http://static1.aljazair24.com/wp-content/themes/aljazair/inc/js/flexslider.min.js
http://static1.aljazair24.com/wp-content/plugins/wysija-newsletters/js/validate/languages/jquery.validationEngine-ar.js
http://static1.aljazair24.com/wp-content/plugins/wysija-newsletters/js/front-subscribers.js
...
Have you tried Cloudflare? Most hosting providers have a built in extension and you dont have go through plugins like WP SuperCache or W3 Total Cache.
I have been having inconsistent behavior with my Django app.
If I login with no www, and then prepend www, it's not authenticated, and all the combinations thereof. (www.mydomain.com and mydomain.com like different sites in terms of auth)
If the authentication code is important, I wrote a middleware based on the tutorial here: http://onecreativeblog.com/post/59051248/django-login-required-middleware
So far I have fixed the issue forcing the appending of www, using PREPEND_WWW = True, but I would still like to understand the issue;)
Does anyone have an idea of what may be going on?
Thanks in advance!
What Zaha Zorg said: Cookies from Django won't work for both a prepended www and non-www domain by default.
However, the deeper issue here is that you're allowing both www and non-www domains of your site to serve identical content. Besides the obvious SEO consequences of having traffic split between the two, you run into issues like these. The proper way to handle this is to redirect all traffic from one to the other (whichever you prefer). The PREPEND_WWW setting you found works perfectly for this. For the opposite (forcing all traffic to non-www), it's recommended to just do a re-write at the server configuration level, such as Apache or Nginx.
You need to look at https://docs.djangoproject.com/en/dev/ref/settings/?from=olddocs#session-cookie-domain
SESSION_COOKIE_DOMAIN
Default: None
The domain to use for session cookies. Set this to a string such as ".lawrence.com" for cross-domain cookies, or use None for a standard domain cookie. See the How to use sessions.
Could it be that cookies depend on the hostname of the server ? This could explain why both domain names are considered different.