Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将.htaccess文件转换为nginx_Php_.htaccess_Nginx - Fatal编程技术网

Php 将.htaccess文件转换为nginx

Php 将.htaccess文件转换为nginx,php,.htaccess,nginx,Php,.htaccess,Nginx,我有下一个项目结构:项目目录和公用文件夹。在项目目录中,我有下一个.htaccess文件: AddDefaultCharset utf-8 RewriteEngine On RewriteRule (.*) public/$1 在公用文件夹中,我有index.php和另外一个.htaccess: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) index.php?$

我有下一个项目结构:项目目录和公用文件夹。在项目目录中,我有下一个.htaccess文件:

AddDefaultCharset utf-8
RewriteEngine On
RewriteRule (.*) public/$1
在公用文件夹中,我有index.php和另外一个.htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?$1 [L,QSA]
如何将此规则重写为nginx

我尝试了在线资源,但他们没有帮助我: 字符集utf-8

location / {
  rewrite ^(.*)$ /public/$1;
  if (!-e $request_filename){
    rewrite ^(.*)$ /index.php?$1 break;
  }
}
试试这个:

server {
    server_name example.com;
    root /path/to/files;
    charset utf-8;
    rewrite (.*) /public/$1;
    location /public/ {
        try_files /public$uri /public$uri/ /public/index.php?$uri$is_args$args;
    }
}
虽然,从外观上看,您只需要将
root
指令设置为
public
,并且不尊重您的“bad.htaccess”。 这将更干净/更安全:

server {
    server_name example.com;
    root /path/to/files/public;
    charset utf-8;
    location / {
        try_files $uri $uri/ /index.php?$uri$is_args$args;
    }
}