Php apache.htaccess到nginx重写规则
我需要从apache更改为Nginx,但是Php apache.htaccess到nginx重写规则,php,apache,.htaccess,mod-rewrite,nginx,Php,Apache,.htaccess,Mod Rewrite,Nginx,我需要从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服务器上放置.ht
.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
但它不起作用。该目录类似于:
# 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
这一切都可以在我的apache安装上运行,但不能在Nginx服务器上运行。
请帮帮我
#
编辑:
原来nginx.conf
文件必须位于根文件夹上方,并且只有在您有权访问根文件夹上方的文件夹时才能访问。像服务器管理员一样,访问也是必需的。Nginx没有htaccess文件。代码需要进入nginx配置文件。另外,尝试将“最后一次”标志添加到重写:
# nginx configuration
autoindex off;
location / {
rewrite .* /index.php last;
}
你找到了吗?是的,还有很多其他的网站。我试着把我的代码放在nginx.conf和nginx.conf.txt的同一个文件夹中,但不起作用。nginx服务器自动删除htaccess文件。代码要放在htaccess文件中吗?文件名是否为nginx.conf,并通过index.php放在根文件夹中?@user3434534否。这在不同的系统上是不同的。如果我无法访问根目录,我是否可以将自己的nginx.conf文件覆盖到我正在使用的目录中?@Medda86不,nginx不是这样工作的。如果您没有访问配置文件的权限,则无法更改nginx的行为。好的,谢谢,我必须与管理人员联系,然后为我设置它。谢谢你的解释。