How to Disable 404 Redirects in WordPress
Ever been through a situation where you tried to access a website and browser displayed ‘Error 404- Page not found’? wonder what just went wrong?
404 are broken links on a website which redirect users to the error page suggesting that the website or some of its content does not exist. This certainly makes users leave the website, this makes it important for webmasters to remove all 404 redirects.
Disabling 404 redirects in a WordPress website can be done by editing its .htaccess file. This guide will let you know about all possible ways to remove 404 redirects considering the type of errors that might appear on a WordPress website.
To begin with the process, you need to:
- Locate the .htaccess file of a WordPress website
The .htaccess file is found in the root folder of WordPress installation. To access the file, you will have to either use FTP – file transfer protocol – or access it via website’s cPanel. Once that the file is accessed force show the hidden files to make changes.
- Create a backup
You cannot risk crashing the website, can you? To enable to process safely, download a copy of WordPress files especially the .htaccess file before making any changes.
Once that you open the .htaccess file you shall find the following code:
# BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress
This chunk of code is the basic added by WordPress however, you might also find other blocks of codes written in the .htaccess file. Do not try to edit any of it as they may contain the basic functionalities of a WordPress website.
- Begin the redirection
The most efficient way of dealing with 404 redirects is to use 301 redirect to bring traffic back to homepage rather than making them view the ‘Error 404-Page not found’. By modifying and pasting the following set of codes in the .htaccess file you can easily do that:
Redirect Individual Page
This code will send website traffic from ‘old page’ to ‘new page’ that you want them to see.
Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect all files from a directory
With this code you will allow users to access files from the directory ‘people’ from ‘www.yoursite.com/
Redirect 301 /people http://www.yoursite.com/
Redirect full website
This code will let you redirect all users that access any page of a website to ‘www.yoursite.com/.
Redirect 301 / http://www.yoursite.com/
Another effective way of optimising redirects is to edit the Permalinks settings.
- Create shorter Permalinks
To shorten the permalinks and make the URL look neat use the following code:
RewriteEngine On RewriteBase / RewriteRule ^category/(.+)$ http://mydomain.com/$1 [R=301,L] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]
Once that the changes are made, save the .htaccess file but do not forget to redirect your website according to the new permalinks.
- Test the website
After that changes are saved, test run the WordPress website to look for any 404 redirects if still found.
There you go, you are done!
You may easily find WordPress compatible plugins to redirect 404s to the homepage. Among these are ‘All 404 Redirect to Homepage’, ‘SEO Redirection Plugin’ and many more.
Let us know how this guide helped you! Have any ambiguities? Ask now!