Register Login

Nginx How to redirect custom 404 page to website correct page

Updated Oct 12, 2018

Hi All,

I want to redirect 404 page genereate by nginx to correct page in my website.

to genereate custom 404 page I added this code in 

/etc/nginx/conf.d/sitename.conf

#To Pass all request to /index.php

#---------------------------------------------

location / {
                    try_files $uri $uri/ /index.php?$args;
                          }

#----------------------------------------------

# To Generate custom 404 page

                location ~ .php$ {
                   try_files $uri =404;
                        error_page  404 /404.php;
                        fastcgi_intercept_errors on;
                        fastcgi_pass unix:/var/php-nginx/sitename.sock;
                        fastcgi_buffers 32 32k;
                        fastcgi_buffer_size 128k;

                }


This Code root all error page to 404.php 

But when i tring to redirect the error url to correct url it wont work

header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: /correctpage/");

the above code is not working

Can u please help me on this

Regard's

 


×