1
ryd994 2015 年 1 月 19 日 大小写混用是什么奇葩坏习惯?
~*只是说/cool/ 和/Cool/都会由这个location块处理,但实际处理时就会找不到文件 如果你只是需要一个quick and dirty的话,可以ln -s cool Cool |
2
ylhawj 2015 年 1 月 19 日 windows是不区分大小写的,所以需要程序中将url统一按照小写或者大写处理就好了。
|
3
iyuyue OP @ryd994 额,想做到不区分大小写,这样用户可以按自己喜欢的方式来输入。类似于Github。可以用alias来实现么?我试了下会陷入循环= =
|
7
ylhawj 2015 年 1 月 19 日 @iyuyue 嗯,这样的处理方法很多种,比如说Google下,http://www.myhack58.com/Article/sort099/sort0102/2014/51879.htm,这样的。
|
9
ryd994 2015 年 1 月 20 日 via Android @iyuyue 如果你只有这一个或者几个路径的话可以rewrite解决。用location ~* 然后里面rewrite到小写,但是要注意加last 防止死循环
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite 不过按照location的匹配顺序,路径是优先于regex,似乎不加也可以……你自己试试吧…… |
10
iyuyue OP @ryd994 抱歉,我试了一下rewrite .* /cool/ last; 然后500了。 能再说的详细一点么?我对nginx的正则有点晕= =
|
12
ryd994 2015 年 1 月 21 日 via Android
你要有两个location啊,一个正则的用来改写,一个静态小写的用来实际提供服务
处理的时候小写的因为是静态规则所以会优先匹配 |
13
ryd994 2015 年 1 月 21 日 via Android
或者你可以试试用break而不是last
|
14
iyuyue OP @ryd994 抱歉。。后来忙别的忘了回复。最后实现的是这样的
location ~ /cool/ { index index.html; .... } location ~* /cool/ { rewrite .* /cool/ last; } |
15
ryd994 2015 年 2 月 10 日
@iyuyue 这…………两次regex你不感到蛋疼么…………
location ^~ /cool/ { index index.html; .... } location ~* /cool/ { rewrite .* /cool/ last; } 这样就最多只需要一次regex,如果进来就是小写的话就不会检查regex |
18
ryd994 2015 年 2 月 10 日
@iyuyue
>If a location is defined by a prefix string that ends with the slash character, and requests >are processed by one of proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass, or >memcached_pass, then the special processing is performed. In response to a request with >URI equal to this string, but without the trailing slash, a permanent redirect with the >code 301 will be returned to the requested URI with the slash appended. 照例说应该是这样,为什么没有我也不知道。 |