flask对tailing slash默认的处理是/abc会指定向/abc/,访问/abc都会访问/abc/,有时候前端大大不希望
后端实现:
@mod.before_request
def clear_trailing():
from flask import redirect, request
rp = request.path
print request.query_string
if rp != '/' and rp.endswith('/'):
rp = rp[:-1]
if len(request.query_string) > 0:
rp = rp + '?' + request.query_string
return redirect(rp)
app.url_map.strict_slashes = False
nginx实现:
在虚拟主机配置中添加一个rewrite规则
rewrite ^/(.*)/$ /$1 permanent;