Solved

create 404 redirect in .htaccess

Posted on 2011-03-19
5
307 Views
Last Modified: 2012-05-11
how would i create a 404 redirect to my home page in a .htaccess file?
0
Comment
Question by:COwebmaster
  • 2
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 333 total points
ID: 35173374
Put this in your .htaccess file:

ErrorDocument 404 /index.html

Open in new window


This will tell your server to redirect to index.html when no page can be found.
0
 

Author Comment

by:COwebmaster
ID: 35173414
tried that but still I get a 404 error.  I have a wordpress site and in my htaccess file I have:

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

0
 
LVL 8

Assisted Solution

by:Rik-Legger
Rik-Legger earned 333 total points
ID: 35173441
I suppose that you get the 404 error from wordpress?
Because looking at your .htaccess everything (even pages that don't exist) will be 'send' to index.php.
If not, maybe you can attach a screenshot so i can see whats going on?
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 167 total points
ID: 35173581
I can show you how I handle the 404 issue in PHP (not .htaccess).  This specifically addresses the issue that my clients seem to have a propensity to write URLs like /results instead of /results.php
<?php // 404handler.php
error_reporting(E_ALL);

if (isset($_SERVER["REQUEST_URI"]))
{
    // IF A PHP SCRIPT IS NOT FOUND GO TO THE HOME PAGE
    if (preg_match('#\.php#i', $_SERVER["REQUEST_URI"]))
    {
        header('Location: /');
        exit;
    }

    // IF A NON-PHP SCRIPT IS NOT FOUND, TRY IT WITH PHP
    $arr = explode('?', $_SERVER["REQUEST_URI"]);
    $arr[0] .= '.php';
    $uri = implode('?', $arr);
    header("Location: $uri");
    exit;
}

// IF NO REQUEST URI
header('Location: /');
exit;

Open in new window

0
 

Author Closing Comment

by:COwebmaster
ID: 35326673
Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now