【问题标题】:URI redirection in NGINXNGINX 中的 URI 重定向
【发布时间】:2017-09-15 11:09:01
【问题描述】:

这是我的第一个问题。

我在 CodeIgniter 中开发了一个 Web 应用程序。它在带有 apache 的 ubuntu 上运行良好。但是当我将它上传到我的服务器时,它不再工作了。服务器使用 NGINX。

我正在使用 .htaccess 从 URL 中删除 index.php。

这是我的 .htaccess 文件:

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

如果我不这样做并保留 index.php,它就可以正常工作。 我该怎么办?

【问题讨论】:

    标签: php apache .htaccess codeigniter nginx


    【解决方案1】:

    nginx 不支持.htaccess。将设置写入/etc/nginx/nginx.conf。

    Nginx 也不支持 Apache 的重写引擎的语法。

    阿帕奇

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

    Nginx 的相同重写(自动转换)

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

    【讨论】:

    • 谢谢,我必须在服务器端进行,而不是在本地系统上。如何在服务器上做到这一点。我在那里没有找到“/etc/nginx/nginx.conf”。
    • 也许你可以找到像/etc/nginx/sites-enabled/yourSite (or default)这样的文件
    • 我找到了 /etc/ 但没有像 Nginx 或其他类似的东西。里面有mydomain_name和webdav等
    猜你喜欢
    • 2020-07-17
    • 1970-01-01
    • 2014-03-08
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 2018-04-19
    • 2019-03-21
    相关资源
    最近更新 更多