【发布时间】:2014-04-24 16:02:35
【问题描述】:
我需要从 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 文件必须位于根文件夹上方,并且只有在您有权访问根文件夹上方的文件夹时才能访问。像服务器管理员访问是必要的。
【问题讨论】:
-
是的和许多其他网站。我尝试将我的代码放在同一文件夹中的 nginx.conf 和 nginx.conf.txt 中,但不起作用。 nginx 服务器会自动删除 htaccess 文件。代码要放在 htaccess 文件中吗?
标签: php apache .htaccess mod-rewrite nginx