加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php – apache .htaccess到nginx重写规则

发布时间:2020-05-25 08:56:32 所属栏目:PHP 来源:互联网
导读:我需要从apache更改为Nginx,但.htaccess不能在Nginx服务器上运行. 我在我的Apache .htaccess中得到了以下内容: RewriteEngine On # always run through the indexfileRewriteRule .$index.php# dont let people peek into directories witho

我需要从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没有htaccess文件.代码需要进入nginx配置文件.另外,尝试在重写中添加“last”标志:
# nginx configuration

autoindex off;

location / {
    rewrite .* /index.php last;
}

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读