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

时间:2015-10-01 16:55:36

标签: php wordpress redirect nginx rewrite

我想将http://test.com/folder1/上的404错误重定向到http://test.php/folder1/index.php

服务器正在使用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个错误重定向到http://test.com/index.php。 404错误应该重定向到每个子文件夹中的index.php。

感谢

0 个答案:

没有答案
相关问题