0

it seems like google links to my page contain a "www." before the domain, this causes security errors since I'm reading data from the canvas and the images will be marked as cross-orign if they are from "www.x.com" rather than "x.com".

So i'm wondering what's the nicest way to redirect people from the url with the www. in it to one without?

(alternately, can I get google to link without the www?)

Thanks

monkeymad2
  • 153
  • 1
  • 11
  • For Google part, check the pages indexed by Google, they should be in the form of `domain.com/...` instead if `www.domain.com/...`. – okm Jun 27 '12 at 05:23

1 Answers1

3

The best way would be to let your webserver (apache/nginx) handle the redirect, instead of doing it in Django.

In nginx it could look something like this:

server {
        listen 80;
        server_name www.example.com;
        rewrite ^(.*) http://example.com:80$1 permanent;
}

Of course you could do it in Django, simply check for the existence of the subdomain www and then redirect to the same URL without this subdomain. In this case you would need to add this logic to all of your views though (could be a decorator for example). Still, its hard to maintain and the better and simpler approach is the one I mentioned above.

Torsten Engelbrecht
  • 13,318
  • 4
  • 46
  • 48
  • +1 agreed. The place for this is at the front end proxy/web server and not in the app. – Burhan Khalid Jun 27 '12 at 04:32
  • 1
    I also agree with @BurhanKhalid. But if you do it in your Django code, don't use view decorators, use a middleware instead. That's where code belongs that should be executed for *all* requests. – Danilo Bargen Jun 27 '12 at 09:03
  • Thanks for pointing me in the right direction. My webhost uses apache so I found this to be useful [link](http://stackoverflow.com/questions/4192948/remove-www-site-wide-force-https-on-certain-directories-and-http-on-the-rest) – monkeymad2 Jun 27 '12 at 10:55