How to Use .HTAccess to Redirect a WordPress 404 Error
Most WordPress themes include a 404.php file that posts a customizable page when visitors click a bad link in your site. If the Web server software can't find this file, your visitors either return to your homepage with little explanation or see a generic "404 page" from your Web host. Make sure that your visitors receive the page that's meant for them by identifying its location in your WordPress site's .htaccess file.
Things You'll Need
- Web host with Apache Web server software
- Host-based file management and text editor
- WordPress theme with 404.php file
- Website administrative user account name and password
- WordPress administrative user account name and password
Instructions
-
-
1
Log in to your host. Open its file manager. Select the WordPress folder. It includes a number of program files as well as an index.php file and the folders wp-admin, wp-content and wp-includes. It may or may not include an .htaccess file. If it does, make a backup copy before you start editing.
-
2
Create a new file If no .htaccess file exists. Otherwise, select the .htaccess file and open your file manager's code editor. Type "ErrorDocument 404 /index.php?error=404" (without quotation marks) in a blank line. If WordPress is installed in a subfolder, precede index.php with the folder's name, as in "ErrorDocument 404 /wordpress/index.php?error=404." Using the ErrorDocument statement allows WordPress to find a 404.php file even if you change themes.
-
-
3
Save the .htaccess file. Don't use an extension, enclose the name .htaccess in quotes to prevent it. Test your settings by logging in to WordPress with its administrative account name and password. Verify that you can access the dashboard, pages, posts and comments.
-
4
Add a bad link and access your home page. Click the new link. If your theme's 404.php page appears, log out. Test access from other user accounts and as a visitor. If there are problems, restore the original .htaccess file (or rename the new file you created), retry the edit and test again. This is why having a backup copy is important.
-
1
Tips & Warnings
If your host's control panel does not include a file manager or code editor, use an FTP client such as FileZilla to download the .htaccess file, then make the edits with your own text editor. Use the FTP client to return the file to your site.
The WordPress documentation includes tips for customizing the content of your 404.php file.
The AskApache Google 404 Plugin can enhance error processing by suggesting alternate sources of the information that the bad link was supposed to contain. This plug-in handles other error conditions in addition to 404.
Back up the .htaccess file before editing. A damaged or corrupt .htaccess file can deny you or your visitors access to your site.
If editing the .htaccess file is unsuccessful, you may have to adjust its access permissions. To edit .htaccess with the WordPress template editor, set .htaccess access permissions to "666 (universal read/write)" or "660 (user and group read/write)." Then, any user with template editing privileges will be able to edit the file.
Many host Web servers use operating systems with case-sensitive file and folder names. Make sure the case of any folder and file names you type matches that of their online counterparts.
References
Resources
- Photo Credit Dynamic Graphics/Dynamic Graphics Group/Getty Images