Forum Moderators: phranque

Message Too Old, No Replies

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

How do you do it?

         

doppelganger

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

10+ Year Member



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?

piramida

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

10+ Year Member



<?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).

jdMorgan

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

WebmasterWorld Senior Member 10+ Year Member



> 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

doppelganger

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

10+ Year Member



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?

closed

2:38 pm on Aug 28, 2003 (gmt 0)

10+ Year Member



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.