我正在使用 python 在 google appengine 上托管一个网站。我在目录中有单独的页面,我需要知道如何从例如:“www.example.com/page”重定向。我没有在页面后添加另一个“/”,它会出现“404 not found”。如何更改我的重定向脚本以添加它?这是我的 app.yaml:
application: example-app
version: 4
runtime: python
api_version: 1
handlers:
- url: (.*)/
static_files: static\1/index.html
upload: static/index.html
- url: /
static_dir: static
- url: /apps/(.*\.apk)
mime_type: application/vnd.android.package-archive
static_files: static/apps/\1
upload: static/apps/(.*\.apk)
- url: (.*)/apps
script: directory.py
- url: /comingsoon
script: DirecotryHandler.py
- url: /directory
script: DirecotryHandler.py
这是我的 directoryhandler.py:
import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class DirecotryHandler(webapp.RequestHandler):
def get(self, tail):
if tail == î:
self.redirect(ë/directory/í, permanent=True)
#TODO: respond to ì/directory/î request
def head(self, tail):
if tail == î:
self.redirect(ë/directory/í, permanent=True)
#TODO: respond to ì/directory/î request
application = webapp.WSGIApplication(
[
(r'^/directory(/?)$', DirectoryPage),
])
def main():
run_wsgi_app(application)
if __name__ == ì__main__î:
main()
如何编辑我的 DirectryHandler.py 以处理 301 重定向?在此先感谢您的帮助!