如何正确地将apache配置转换为nginx?给定$request_filename



在/projects/子文件夹中,我有一个包含以下内容的htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteRule . /template/template-project.php [L]

如果/projects/中的子文件夹不包含索引php或html,则可以进行重定向。

好的,在线转换器给了我这个结果:

location / {
if (!-e $request_filename){
rewrite ^(.*)$ /template/template-project.php break;
}
}

我发现这是一个不完整的配置,根本不起作用。我尝试过不同的组合,但在很多情况下我都会出现403的错误。

这种类型的配置应该是什么样子?

得到了答案:

location /projects {
index index.html index.php /template/template-project.php;
try_files $uri $uri/ /template/template-project.php?$query_string;
}

最新更新