所以这是一个很奇怪的问题!我有这些nginx诗节。我使用了一个在线工具将.htaccess规则转换为支持nginx的规则。
location / {
rewrite ^/(([^/]+/)*)login/$ /login.php?path=$1&$query_string break;
rewrite ^/(([^/]+/)*)comment/$ /comment.php?path=$1&$query_string break;
rewrite "^/([^/]+/){4}$" /asset.php break;
rewrite ^/(\d\w+)/$ /public.php?ticket=$1 break;
rewrite "^/(\d\w+)/([^/]+/){2}?$" /public-asset.php?ticket=$1 break;
if (!-e $request_filename){
rewrite ^/(([^/]+/)*) /index.php?path=$1&$query_string break;
}
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/vh1-fpm.sock;
include fastcgi_params;
}转到https://example.test/ ok
打开https://example.test/login/,所有的代码都会被淹没在屏幕上。
正则表达式路由之所以起作用,是因为发生了重定向。但是一旦重定向完成,就像屏蔽的.php文件没有被捕获一样。如果我将/检查封装在PHP块中,所有这些问题都可以解决。
发布于 2020-05-29 14:39:22
如果要在different location块中处理重写的URI,则不能使用rewrite ... break。
用法:rewrite...last
此外,没有必要在重写的URI的末尾添加&$query_string,因为rewrite无论如何都会这样做的,除非重写的URI以?结尾。
详情请参见this document。
https://stackoverflow.com/questions/62072825
复制相似问题