?
Solved

create 404 redirect in .htaccess

Posted on 2011-03-19
5
Medium Priority
?
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 1332 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 1332 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 668 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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

762 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