我的服务器使用nginx,我的域名服务于静态HTML网页,即
http://server.com/download.html
出于各种原因,我希望用户能够通过以下url获取download.html :
http://server.com/download.html (works) http://server.com/download (works) http://server.com/download/ (works not)
我得到了前两个工作,但最后一个总是返回/404.html。
try_files能够做我想做的,还是我必须使用rewrite指令呢?
我的nginxconfiguration:
location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri.html $uri/ /404.html; # auth_basic "Restricted"; # auth_basic_user_file /var/www/upscaledb/htpasswd; }
谢谢你,克里斯托夫
如果添加一个位置来重写URI而不使用结尾的斜杠,那么现有的location /和try_files指令可以完成剩下的工作:
location ~ ./$ { rewrite ^(.+)/$ $1 last; }