Solved

create 404 redirect in .htaccess

Posted on 2011-03-19
5
308 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to dynamically set the form action using jQuery.

863 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