这应该做你需要的:
https://gist.github.com/873098
说明:在 App Engine Python 中,可以使用正则表达式作为 URL 处理程序,app.yaml
并将所有 URL 重定向到静态文件的层次结构。
示例app.yaml
:
application: your-app-name-here
version: 1
runtime: python
api_version: 1
handlers:
- url: /(.*\.css)
mime_type: text/css
static_files: static/\1
upload: static/(.*\.css)
- url: /(.*\.html)
mime_type: text/html
static_files: static/\1
upload: static/(.*\.html)
- url: /(.*\.js)
mime_type: text/javascript
static_files: static/\1
upload: static/(.*\.js)
- url: /(.*\.txt)
mime_type: text/plain
static_files: static/\1
upload: static/(.*\.txt)
- url: /(.*\.xml)
mime_type: application/xml
static_files: static/\1
upload: static/(.*\.xml)
# image files
- url: /(.*\.(bmp|gif|ico|jpeg|jpg|png))
static_files: static/\1
upload: static/(.*\.(bmp|gif|ico|jpeg|jpg|png))
# index files
- url: /(.+)/
static_files: static/\1/index.html
upload: static/(.+)/index.html
# redirect to 'url + /index.html' url.
- url: /(.+)
static_files: static/redirector.html
upload: static/redirector.html
# site root
- url: /
static_files: static/index.html
upload: static/index.html
为了处理对不以可识别类型( , 等)结尾的 URL 的请求,.html
或者.png
您/
需要将这些请求重定向到URL + /
以便index.html
为该目录提供服务。我不知道在 .js 中执行此操作的方法app.yaml
,所以我添加了一个 javascript 重定向器。这也可以用一个很小的 python 处理程序来完成。
redirector.html
:
<!DOCTYPE html>
<html lang="en">
<head>
<script language="JavaScript">
self.location=self.location + "/";
</script>
</head>
<body>
</body>
</html>