【问题标题】:How properly convert the apache config to nginx? Given $request_filename如何正确地将 apache 配置转换为 nginx?给定 $request_filename
【发布时间】:2022-01-13 18:44:26
【问题描述】:

在 /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 错误。

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

【问题讨论】:

    标签: nginx url-rewriting


    【解决方案1】:

    得到答案:

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

    【讨论】:

      猜你喜欢
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-22
      • 2014-09-24
      • 2012-08-25
      • 1970-01-01
      相关资源
      最近更新 更多