我有一个Nginx位置指令的问题。 我需要能够通过fastcgi发送任何URI,以便它最终在一个PHP框架。 但是我也想build立一个规则,任何以/用户开头的URI都被redirect(比方说http://www.google.com )。 所以我就是这样做的:
location ~* ^/users*$ { rewrite ^ http://www.google.com? permanent; } location ~* \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_intercept_errors on; # to support 404s for PHP files not found fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
我可以去任何URL,它会通过我使用的PHP框架发送,所以部分工作。 但是,/用户*redirect不起作用。 如果我注释掉第二个位置方向(对于PHP文件),/ users *redirect工作,但实际上在将文件index.phpredirect到http://www.google.com之前将其作为文件下载。
我怎样才能达到这个目的?
正则expression式^/users*$可能不符合你期望它匹配。 像^/users.*$或^/users这样的东西将会更具包容性。