我需要从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当我在Nginx服务器上放置一个.htaccess时,服务器会删除该文件。我必须将.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文件必须位于根文件夹的上方,并且只有在访问根文件夹之上的文件夹时才能访问。就像服务器一样,管理访问是必要的。
发布于 2014-03-18 19:34:01
Nginx没有htaccess文件。代码需要进入nginx配置文件。另外,尝试在重写中添加“最后”标志:
# nginx configuration
autoindex off;
location / {
rewrite .* /index.php last;
}https://stackoverflow.com/questions/22488421
复制相似问题