Redirect to home page on 404 – htaccess

Redirect to home page on 404 – htaccess

How to redirect to home page on page not found 404

If you have a page that is not found, then google and others will penalize your site for not finding the page. Hence, you should handle that internally.

At least the easiest thing one can do is to redirect the site to the home page using .htaccess directives.

Homepage redirection 404

First create a .htaccess file if you don’t have one yet. Place this .htaccess file in the root of the website.

Then add the following line in the .htaccess file.

Options -MultiViews
RewriteBase /
RewriteEngine On
#if you have other redirect rules, have them here
#put this at the end of the file.
ErrorDocument 404 /

Mind you, the page you are going to redirect to should be relative path.
On the above file, those starting with # are comments and won’t be read by the server.

Hope it helps. Let me know if this helps you or if you have better method by leaving the comment down.

See how you would solve these known algorithm problems

Find longest palindrom from sequence of characters

Find the pairs that makes K Complementary in the given array java solution

Kadane’s algorithm in C – Dynamic Programming

Java solution for checking anagram strings – tell if phrases are anagrams

Array reversal in Recurrsion

Finding missing numbers from billion sequential number list file

testing k complementary pairs algorithm with junit

Implementing tokenizer and adding tokens to the linked list

Check if there are three numbers a, b, c giving a total T from array A

Find the first occurence of number in the sorted array

Leave a Reply

Your email address will not be published. Required fields are marked *