Social Icons

Monday, July 22, 2013

Redirecting "not found" pages in to a common page using htaccess

Lets Start

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ comingsoonpage.php

The following procedure, guides on how to redirect.
  1. If you are using cPanel, log into front-end and click on “File Manager” application. Make sure you enable the hidden file viewers.
  2. Go to the root folder of the website & edit or create ”.htaccess” file.
  3. Add the following code & replace YOURURL with the URL where you want the error 404 page redirected to.
  4. Click save & you are done.
1
ErrorDocument 404 http://YOURURL to redirect from the 404 error 

You can do it in your .htaccess file which should be in your site root directory. 
In your .htaccess file add this line:
ErrorDocument 404 /error404.htm (or any name you like)

Create a HTML page such as error404.htm (or any name you like) That page can have text saying something nice like "Sorry that page doesn't seem to exist here" or whatever... 
In the HEAD section of the page put:
<meta http-equiv=REFRESH CONTENT="5; URL=http://your-site-URL/"> 
That page will be viewed for 5 seconds and then redirect to your-site-URL/


or you could leave out the meta refresh and just have text and a link to your home page.

No comments: