NGINX中的URI重定向

时间:2017-09-15 11:09:01

标签: php apache .htaccess codeigniter nginx

这是我的第一个问题。

我在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比它工作正常。 我该怎么办?

1 个答案:

答案 0 :(得分:0)

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

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

<强>的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;
  }
}