Welcome to WebmasterWorld Guest from 34.201.121.213

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Can you change 404s to 301s using .htaccess or mod_rewrite.

How do you do it?

     
6:59 pm on Aug 27, 2003 (gmt 0)

New User

10+ Year Member

joined:May 30, 2003
posts:5
votes: 0


Hello everyone.

I've inherited a couple of websites that have been redesigned 4 or 5 times in the last couple of years. There are numerous pages that are either moved/gone now but still listed in search engines or present with no links from the home pages but still getting visitors.

I'm looking for a way to catch 404 errors and return a 301 redirect to the sites' front pages. I think that this would eventually take the pages that are still listed in the search engines out of the search engines with losing the traffic that the links are currently bringing in.

The problem is that there are dozens of these missing/moved pages mixed in with dozens of pages that are still present in their original locations and I can't figure out a way to do a blanket conversion of 404 errors to 301 redirects that won't affect serving the pages that ARE still there.

Does anyone have any ideas or comments on how to do this? Or am I stuck with creating a 301 redirect for each individual missing/moved page?

8:19 pm on Aug 27, 2003 (gmt 0)

New User

10+ Year Member

joined:Aug 21, 2003
posts:13
votes: 0


<?php
header("HTTP/1.0 301 Moved Permanently");
header("Location: [website.com...]
exit();
?>

in your custom errorpage would do the trick.

(same could be done with asp/jsp I think).

9:52 pm on Aug 27, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


> Does anyone have any ideas or comments on how to do this? Or am I stuck with creating a 301 redirect for each individual missing/moved page?

If you wish to redirect the old URL to a new equivalent-page URL, and the two URLs have nothing in common, then you will be stuck redirecting each one indvidually.

If there is any commonality, you may be able to take advantage of it to reduce the number of redirect directives. It all depends upon the exact details of the new and old naming system, and if there is, in fact, a system.

Jim

1:53 pm on Aug 28, 2003 (gmt 0)

New User

10+ Year Member

joined:May 30, 2003
posts:5
votes: 0


Unfortunately there is little or no commonality. I was hoping to redirect the moved pages to the main page of the site. Like [example.com...] So I have to make an entry for each page? I can't 'use a 'wildcard' entry?
2:38 pm on Aug 28, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Aug 20, 2003
posts:255
votes: 0


doppelganger,

Do you mean something like this?


RewriteEngine on
RewriteCond %{REQUEST_URI} !-f
RewriteRule \.html$ http://www.mysite.com/index.html [NC,R=301,L]

If the file doesn't exist, and its extension is .html (not case sensitive), permanently redirect the request to mysite.com's index.html file.