Pretty URLs in Google App Engine

强颜欢笑 提交于 2019-11-27 02:14:18

问题


I want to pass a parameter 'A1B2C3' to a GWT application based on Google App Engine. I do it like www.example.com/index.html?key=A1B2C3. Although it's working, I'd like to use pretty URLs. Is it possible to do URL rewriting on Google App Engine? I couldn't find out how.

www.example.com/A1B2C3

instead of

www.example.com/index.html?key=A1B2C3

I'm using Google App Engine and GWT. All in Java.


回答1:


This is a cool question. I figured out how to do it for python as well.

app.yaml:

- url: /test/(.*)
  script: test.py \1

test.py:

#!/usr/bin/env python

import sys

def main():           
  for arg in sys.argv:
     print arg

if __name__ == '__main__':                               
  main()



回答2:


You need to configure the application (see here). In other words, you need to "wire" the patterns you want.

From the manual, an example:

<servlet-mapping>
    <servlet-name>redteam</servlet-name>
    <url-pattern>/red/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>blueteam</servlet-name>
    <url-pattern>/blue/*</url-pattern>
</servlet-mapping>



回答3:


Try UrlRewriteFilter: http://tuckey.org/urlrewrite/ (or github repo) it is a plain ol' Java EE filter, so it should work.




回答4:


Save yourself some time and use Restlet. You can do exactly this and I've done this in two different projects. It's quite straight forward. If you need some help, let me know.




回答5:


I would probably use PrettyFaces, http://ocpsoft.com/prettyfaces/ which allows you to do URL-mappings directly on top of an existing application.

You just configure something like this in the pretty-config.xml file:

<url-mapping>
   <pattern value="/my/pretty/url" />
   <view-id value="/my/existing/url" />
</url-mapping>

Or if you want to rewrite parameters, you can do this:

<url-mapping>
   <pattern value="/my/pretty/url/#{param}" />
   <view-id value="/my/existing/url" />
</url-mapping>

And this means that any urls (inbound) now become:

/my/pretty/url/value -> /my/existing/url?param=value

And outbound your URLs will look like this in HTML pages and in redirects:

/my/existing/url?param=value -> /my/pretty/url/value

So it's easy to add on to your current apps.




回答6:


Here is another project that I think may really help you:

It's called restful-gwt... it's pretty slick too: http://code.google.com/p/restful-gwt/

Good luck!




回答7:


This is the best approach I found so far for implementing URL rewrite GAE Python



来源:https://stackoverflow.com/questions/2297056/pretty-urls-in-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!