2017-05-08 6 views
0

になります。404 Not Foundrobots.txtに、HTTPからアクセスするにはHTTPSrobots.txtにアクセスする必要があります。robots.txtへのアクセスは、http://www.yamlで

私だけapp.yaml構成でHTTPSへのアクセスを制限する方法を見つけることができませんでしたので、私はそのためのハンドラを記述することにしましたが、次のエラーました:私が持っているapp.yaml

google.appengine.api.yaml_errors.EventError: Unexpected attribute "script" for mapping type static_files.  

を:

- url: /robots.txt 
    script: main.application 
    static_files: static/\1 
    upload: static/robots.txt 

このような状況を処理する最善の方法は何ですか?

答えて

0

シンプルなハンドラが行います。

app.yamlを

- url: /robots_file 
    static_files: static/robots.txt 
    upload: static/robots.txt 

views.pyを:

from google.appengine.api.urlfetch import fetch 

class RobotsTxtHandler(webapp2.RequestHandler): 

    def get(self): 
     if self.request.url.startswith('https'): 
      robots = fetch('{}/robots_file'.format(SITE_URL)) 
      return self.response.write(robots.content) 
    raise errors.Http404 

urls.py:アプリで設定し

urls = [ 
    ('/robots.txt', views.RobotsTxtHandler), 
] 
0

secure: always。あなたのハンドラーのためのyaml。

ドキュメント:あなたのケースではhttps://cloud.google.com/appengine/docs/standard/python/config/appref

secure: always - Requests for a URL that match this handler that do not use HTTPS are automatically redirected to the HTTPS URL with the same path. Query parameters are preserved for the redirect.

- url: /robots.txt 
    static_files: static/robots.txt 
    upload: static/robots.txt 
    secure: always 
+0

クローラはリダイレクトを無視しているとして、私の場合、それは、助けにはなりません、そして、彼らのように、HTTPS/robots.txtのをおごりますよhttp/robots.txt。 – Pythonist

+0

サイトhttpsだけを作成する必要がある場合は、すべてのハンドラに対して常にsecure:alwaysを指定し、正規のmetaタグをHTMLで設定する必要がありますか?あなたはhttp://DebtsTracker.io/で私がどのようにそれを行うかを確認することができます –

関連する問題