在Google App Engine中关闭区分大小写的网址 [英] Switch off case sensitive URLs in Google App Engine

查看:106
本文介绍了在Google App Engine中关闭区分大小写的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近将公司网站移至Google应用引擎。我们遇到了网站中某些链接的大小写敏感问题。当服务器上的相应文件夹为小写时,某些链接为大写。这在我们的旧windows服务器上不是问题。 Google应用引擎似乎对网址区分大小写。这导致链接断开。

We recently moved our company website to Google app engine. We have encountered case sensitivity problems with some of the links in our website. Some links are uppercase when the corresponding folders on the server are lowercase. This was not an issue on our old windows server. Google app engine appears to be case sensitive with URLs. This is causing broken links.

有谁知道是否有办法让我们的URL在Google应用引擎上不区分大小写?

Does anyone know if there is a way to make our URLs work case insensitively on Google app engine?

推荐答案

这是用于静态文件还是动态处理程序?对于动态处理程序,您可以轻松编写一段WSGI中间件,它可以降低所有URI的数量:

Is this for static files or dynamic handlers? for dynamic handlers, you can easily write a piece of WSGI middleware that lower-cases all URIs:

def lower_case_middleware(environ, start_response):
  environ['SCRIPT_NAME'] = environ['SCRIPT_NAME'].lower()
  environ['PATH_INFO'] = environ['PATH_INFO'].lower()
  return application(environ, start_response)

请注意,这不是App Engine中的'错误' - URLs大小写敏感,并且事情做的唯一原因是因为Windows,不像大多数其他平台,忽略大小写。

Note that this isn't a 'bug' in App Engine - URLs are case sensitive, and the only reason things did work is because Windows, unlike most other platforms, ignores case.

对于静态文件,添加一个只接受小写字母的静态处理程序文件名以及接受这两种情况的文件名的动态处理程序:

For static files, add a static handler that only accepts lower case filenames, and a dynamic handler that accepts filenames of either case:

handlers:
- url: /static/([^A-Z]+)
  static_files: static/\1
  upload: static/.*
- url: /static/.*
  handler: tolowercase.py

现在编写'tolowercase.py',一个redir处理函数将任何混合大小写文件的文件名转换为小写版本:

Now write 'tolowercase.py', a handler that redirects any mixed case filename to the lower-cased version:

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class LowerCaseRedirecter(webapp.RequestHandler):
  def get(self, path):
    self.redirect('/static/%s' % (path.lower(),))

application = webapp.WSGIApplication([('/static/(.*)', LowerCaseRedirecter)])

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()

编辑:为静态文件添加了一个解决方案。

Added a solution for static files.

这篇关于在Google App Engine中关闭区分大小写的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆