以下假设两种情况,第一种是网站在根目录下,另一个是网站在二级目录下的两种情况。

假设网站在根目录下,即首页访问方式是:https://10.1pxeye.com/

Apache下的写法:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Nginx下的写法:
if (!-f $request_filename){
	set $rule_1 1$rule_1;
}
if (!-d $request_filename){
	set $rule_1 2$rule_1;
}
if ($rule_1 = "21"){
	rewrite /. /index.php last;
}

假设网站在二级目录ninja文件夹里,即首页访问方式是:https://10.1pxeye.com/ninja/

Apache下的写法:
RewriteEngine On
RewriteBase /ninja/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ninja/index.php [L]
Nginx下的写法:
if (!-f $request_filename){
	set $rule_1 1$rule_1;
}
if (!-d $request_filename){
	set $rule_1 2$rule_1;
}
if ($rule_1 = "21"){
	rewrite /. /ninja/index.php last;
}

使用方法:

将上面对应的nginx的代码放到nginx的配置文件nginx.conf里的对应网站的server区域里。nginx.conf没有太固定的位置,看你怎么配置的了。一般当然会在nginx的安装目录里啦。
下面是网站10.1pxeye.com的Nginx的配置文件,可做一下参考:

server
{
    listen 80;
	listen 443 ssl http2;
    server_name 10.1pxeye.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/10.1pxeye.com;
    
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }

    ssl_certificate    /etc/letsencrypt/live/10.1pxeye.com/fullchain.pem;
    ssl_certificate_key    /etc/letsencrypt/live/10.1pxeye.com/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    error_page 497  https://$host$request_uri;

    error_page 404 /404.html;
    error_page 502 /502.html;

    include enable-php-72.conf;
    
    include /www/server/panel/vhost/rewrite/10.1pxeye.com.conf; 
    #这里可以替换成上面所示的nginx代码。也可以按照上面这一样所示的方法另调用一个.conf文件,将rewrite代码写到该文件里。
    
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    location ~ \.well-known{
        allow all;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log off;
        access_log off;
    }
    
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log off;
        access_log off; 
    }
  
    access_log  /www/wwwlogs/10.1pxeye.com.log;
    error_log  /www/wwwlogs/10.1pxeye.com.error.log;
}