Redirect *.appspot.com to custom domain: Google app engine (Django)

巧了我就是萌 提交于 2019-12-04 06:42:07

问题


I'm directly putting here some sample code of mine to get better picture.

url.py

(r'^robots\.txt$', 'myapp.views.robots'),
(r'^$', 'myapp.views.home'),

views.py

def home(request):
...my code
return render_to_response(request, 'myapp/home.html', locals())

models.py
class user_sessions(db.Model):
   email_id = db.StringProperty(default='')
   user_id = db.IntegerProperty(default=0)
   class Meta:
      db_table = 'user_sessions'
      verbose_name = 'User Session'
      verbose_name_plural = 'User Sessions'
   def __unicode__(self):
      return self.user_id

My website is hosted on mydomain.com & I can access the using mydomain.appspot.com too. But the main issue i'm facing with SEO.

in robots.txt i'm calling my mydomain.com/sitemap.xml

but when i search on google & sees the result then it shows the result with appspot url but not with my actual domain url.

Then i got an idea of to redirect appspot.com to mydomain.com

But really i don't know how to do that globally in my app.

Could anyone help out for the same?


回答1:


If your custom domain is working, add a canonical tag to your pages. This should notify search engines which domain you prefer when same content is available from multiple domains.

<link rel="canonical" href="https://example.com/" />

https://en.wikipedia.org/wiki/Canonical_link_element



来源:https://stackoverflow.com/questions/35286042/redirect-appspot-com-to-custom-domain-google-app-engine-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!