Disable case sensitive urls in Google App Engine

We recently transferred our company website to Google. We encountered case sensitivity issues with some of the links on our website. Some links are uppercase if the corresponding folders on the server are lowercase. This is not a problem on our old Windows server. The google apps engine seems to be case sensitive with urls. This causes broken links.

Does anyone know if there is a way to make our url work disrespectfully in a google app?

+2


source to share


2 answers


Is it for static files or dynamic handlers? for dynamic handlers, you can easily write a piece of WSGI middleware that lists all the 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)

      

Note that this is not a "bug" in App Engine. URLs are case sensitive and the only reason this works is because Windows, unlike most other platforms, ignores case.

For static files, add a static handler that only accepts lowercase filenames and a dynamic handler that accepts filenames anyway:



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

      

Now write 'tolowercase.py', a handler that will redirect any mixed case filename to the bottom-windowed 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()

      

Edit: Added solution for static files.

+7


source


I don't know the built-in way.



All I can think of is that you will need to create a handler for /(.*) and then write code to forward requests to the handlers you want.

0


source







All Articles