Redirect *.appspot.com to custom domain: Google ap

2020-05-03 01:20发布

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条回答
ゆ 、 Hurt°
2楼-- · 2020-05-03 02:09

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

查看更多
登录 后发表回答