我需要从apache更改为Nginx,但.htaccess
在Nginx服务器上不工作。
我得到以下在我的Apache .htaccess
:
RewriteEngine On
# always run through the indexfile
RewriteRule .$ index.php
# don't let people peek into directories without an index file
Options -Indexes
当我把.htaccess
放在Nginx服务器上时,该文件被服务器删除。在什么样的文件中,我必须把.htaccess
数据(名称和后缀请),它应该如何为Nginx重写,我把文件放在哪里?
我希望所有子目录文件都通过我的index.php
文件,这样我就可以从我的index.php
文件中包含特定的文件…
我试过这样做:
# nginx configuration
autoindex off;
location / {
rewrite .$ /index.php;
}
但它不起作用。目录如下所示:
── root
├── folder1
│ └── folder2
│ └── file.php
└── index.php
所以如果我请求root/folder1/folder2/file.php
,我希望服务器加载root/index.php
,因为我仍然有服务器url请求,我可以从我的index.php
root/folder1/folder2/file.php
这一切都可以在我的apache安装,但不是在Nginx服务器。请帮帮我。
#编辑:事实证明,nginx.conf
文件必须在根文件夹之上,只有在您有权访问根文件夹之上的文件夹时才能访问。
Nginx没有htaccess文件。代码需要进入nginx配置文件。另外,尝试在重写中添加"last"标志:
# nginx configuration
autoindex off;
location / {
rewrite .* /index.php last;
}