Php 将404错误重定向到子目录中的索引文件

Php 将404错误重定向到子目录中的索引文件,php,wordpress,redirect,nginx,rewrite,Php,Wordpress,Redirect,Nginx,Rewrite,我想将404错误重定向到 服务器正在使用nginx和php-fpm运行。下面给出了当前虚拟主机 server { listen x.x.x.x:80; server_name test.com www.test.com; access_log off; #error_log /dev/null; error_log /var/log/nginx/error.log; root /

我想将404错误重定向到

服务器正在使用nginx和php-fpm运行。下面给出了当前虚拟主机

server {
          listen x.x.x.x:80;
          server_name test.com www.test.com;

          access_log off;
          #error_log  /dev/null;
      error_log /var/log/nginx/error.log;

          root /home/test/public_html;

          location / {
                index index.php;
                location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
                expires 7d;
                }
                location ~* \.php$ {
                fastcgi_index   index.php;
                fastcgi_pass   unix:/var/run/php-fpm/test.sock;
                include         fastcgi_params;
                fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
                fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
                }
          }

          if (!-e $request_filename)
          {
                rewrite ^(.+)$ /index.php?q=$1 last;
          }

          location ~ /\.ht {
          deny all;
          }
       }
目前有404个错误正在重定向到。404错误应重定向到每个子文件夹中的index.php

谢谢