【问题标题】:Migration failed from htaccess to nginx configuration从 htaccess 迁移到 nginx 配置失败
【发布时间】:2019-04-09 08:00:40
【问题描述】:

我正在从 .htaccess 迁移到 nginx.conf 文件,但迁移规则无法按预期工作。 这是我要迁移到 nginx 的 .htaccess 的内容。

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]

这是我迁移的 nginx.conf 的内容:

index index.php

location / {
    rewrite ^(.*)$ /index.php?$1 break;
}

请让我知道这有什么问题以及如何让 nginx conf 文件正常工作。

问候。玉铭

【问题讨论】:

  • 您在index 语句的末尾缺少;。另外,尝试将rewrite 语句替换为:try_files $uri $uri/ /index.php?$uri;
  • 感谢您的评论。试过了,效果很好。

标签: .htaccess ubuntu nginx mod-rewrite npm


【解决方案1】:

那些 .htaccess 语句执行与 Nginx try_files 指令类似的功能。

试试:

location / {
    try_files $uri $uri/ /index.php?$uri;
}

详情请见this document

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 2014-02-17
    • 2014-12-23
    • 1970-01-01
    • 2023-03-07
    相关资源
    最近更新 更多