I have defined in my server block:
server {
error_page 401 403 404 /custom_404.html;
location = /custom_404.html {
root /var/www/html;
internal;
}
error_page 500 502 503 504 /custom_50x.html;
location = /custom_50x.html {
root /var/www/html;
internal;
}
}
However, whenever there is a 404 error, this doesnt go through Nginx but it goes through Wordpress redirect.
Same happens with 500 errors. The error page I have defined in Nginx, is not displayed at all. I am getting the default 500 blank screen.
Any ideas on what could be wrong? I believe my code is correct.
I have defined in my server block:
server {
error_page 401 403 404 /custom_404.html;
location = /custom_404.html {
root /var/www/html;
internal;
}
error_page 500 502 503 504 /custom_50x.html;
location = /custom_50x.html {
root /var/www/html;
internal;
}
}
However, whenever there is a 404 error, this doesnt go through Nginx but it goes through Wordpress redirect.
Same happens with 500 errors. The error page I have defined in Nginx, is not displayed at all. I am getting the default 500 blank screen.
Any ideas on what could be wrong? I believe my code is correct.
Share Improve this question asked Nov 3, 2018 at 20:04 JoaMikaJoaMika 6986 gold badges27 silver badges58 bronze badges 1- If WordPress is correctly configured/installed, then WP will process al the input, because everything is redirected to index.php and therefore WordPress also handles the error pages. Look at my answer below to add your own WP error pages. Good luck! – Remzi Cavdar Commented Nov 4, 2018 at 0:07
1 Answer
Reset to default 1Warning
Before you get started, I highly recommend you to create a child theme to safely modify the current theme you’re using. That way, if you need to update your theme, your changes won’t be overwritten.
Modifying your current error page
If your theme already has a custom error page, look for a 404.php
file in your theme's root directory (/wp-content/themes/your-theme/404.php
) and copy it into your child theme’s folder under (/wp-content/themes/your-theme-child/404.php
). Modify this to your liking.
Creating an error page
If your theme doesn’t have a 404 error page set up, you could create one, but instead of creating an error page from scratch, you could copy your theme’s page.php
file to your child theme directory and rename it 404.php
(/wp-content/themes/your-theme-child/404.php
) and modify this to your liking.
If you want to cover any other types of errors / HTTP Status Codes repeat the steps above and just rename the file to reflect the type of error page you want to create such as 404.php
or 403.php
.
See a list of HTTP Status Codes:
- https://httpstatuses (for short explanation)
- https://en.wikipedia/wiki/List_of_HTTP_status_codes (for detailed information)
If you are unable to create a child theme or don't want to create one, you could always use a plugin: https://wordpress/plugins/404page/
Sources:
- https://codex.wordpress/Creating_an_Error_404_Page
- https://premium.wpmudev/blog/customize-error-pages-wordpress/
NGINX
Nginx is not my expertise, I use Apache. So bear with me:
# define error page
error_page 404 = @notfound;
# error page location redirect 302
location @notfound {
return 404 /custom-error-page;
}
In your php block put the fastcgi_intercept_errors
set to on
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
# intercept errors for 404 redirect
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
See for more information: https://guides.wp-bullet/nginx-redirect-404-errors-to-homepage-wordpress/