views:

213

answers:

2

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.

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

A: 

I don't know of a built in way.

All I can think is that you would need to create a handler for /(.*) and then write some code to forward on the requests to the correct handlers from there.

Gareth Simpson
+5  A: 

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)

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

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()

Edit: Added a solution for static files.

Nick Johnson
I am getting error as 'Unexpected attribute 'handler'
Pradeep Kumar Mishra
I am a newbie to AppEngine. Can you explain me how to achieve this.
Pradeep Kumar Mishra
You need to paste your code somewhere for me to help. Perhaps start a new question?
Nick Johnson
put in following question..http://stackoverflow.com/questions/3512338/google-appengine-case-insensitive-for-all-url-request-how
Pradeep Kumar Mishra