2.4 C
New York
Sunday, February 5, 2023

Nginx How to redirect custom 404 page to website correct page

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 


#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



Related Articles


Please enter your comment!
Please enter your name here

Latest Articles