Mobile app version of vmapp.org
Login or Join
Becky754

: Htaccess redirecting 404 URLs to Index page I am trying to setup my htaccess file such that all 404 pages are permanently redirected to the home/index page using 301. After I configure the

@Becky754

Posted in: #Htaccess

I am trying to setup my htaccess file such that all 404 pages are permanently redirected to the home/index page using 301. After I configure the htaccess file I try to test that it is working correctly by typing in a bogus URL such as site.com/asdf to see if the 404 will redirect. It does not, it just displays the page not found message from WordPress and fails to redirect to the homepage.

The code I am using (below) seemed to be working over on Stack Overflow (link, 2nd reply). I have even tried creating a PHP script to use with htaccess to redirect 404's, but still the same result, no redirection.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]
# END WordPress

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Becky754

2 Comments

Sorted by latest first Latest Oldest Best

 

@Pope3001725

All you have to do is open your 404.php file in your theme’s folder. If it doesn’t exist, then create a blank php file. Paste the following code in there:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>

10% popularity Vote Up Vote Down


 

@Radia820

You could use: ErrorDocument 404 /index.php but word of caution... 404's are perfectly normal if the page no longer exists, for user experience you should only ever use a 301 redirect if the page that no longer exists is going to a equal page.. i.e about cars to cars, about rabbits to rabbits.

Using dozens to hundreds of 301's that are undesirable for your audience can result in a negative experience and Google dislikes this behavior. Only ever redirect a 404 page to a relevant page, otherwise leave the 404 or use 410 gone. Users from 404 pages can easily navigate to other pages should they want too, let them have the choice.

Unless there's thousands of similar urls you should use redirect 301 rather than rewrite, simply use:

redirect 301 /old-url/ www.yourdomain.com/new-url/

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme