【问题标题】:.htacces to Nginx rewrite rule.htaccess 到 Nginx 重写规则
【发布时间】:2020-01-10 01:00:58
【问题描述】:

我需要一些帮助来将这个 .htaccess 重写规则转换为 nginx。

RewriteEngine On Options +FollowSymLinks Options -Indexes RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule . index.php [L,QSA]

【问题讨论】:

    标签: .htaccess nginx url-rewriting


    【解决方案1】:

    您的.htaccess 是标准的前端控制器模式,例如你有一个单独的引导 PHP 文件来处理对 SEO 友好 URL 的请求。

    在 NGINX 中,标准做法是对该模式使用 try_files 指令,如下所示:

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    

    上面对应于你的配置的底部 3 行:

    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule . index.php [L,QSA]
    

    最上面的行不需要转换为 NGINX,因为它们已经是 NGINX 中的默认值:

    • 重写模块已启用
    • 遵循符号链接
    • 目录列表已关闭

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-24
      • 2014-06-30
      • 2016-08-09
      • 1970-01-01
      • 2013-02-27
      • 2020-10-02
      • 1970-01-01
      • 2014-10-30
      相关资源
      最近更新 更多