我需要从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
文件必须位于根目录之上,并且只能访问到根目录之上的文件夹。需要具备服务器管理员权限才能访问。