4

We have a client that is closing its doors. We want to redirect all traffic that goes to their domain to a new page index.html with a few images in the _img subdirectory. (The page explains what happened, what current customers can expect with their current orders, etc.)

I've read about possibly using HTTP 410 Gone as the best way to technically explain to bots, etc. that the site is not there, isn't coming back and isn't providing a forwarding address. What would be the best way to do this in an .htaccess file, and direct users to the new index.html?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Ben Dyer
  • 205
  • 1
  • 4
  • 7
  • possible duplicate of [.htaccess 301 redirect all pages on old domain to a single page on new domain](http://stackoverflow.com/questions/15057146/htaccess-301-redirect-all-pages-on-old-domain-to-a-single-page-on-new-domain) – mattdm Jul 10 '14 at 03:04

3 Answers3

10

You can use mod_rewrite for this.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.html$ index.html [L,R=410]

This rule will rewrite requests to non-existing files to index.html and send the 410 status code along with the response. But this requires Apache 2 as R=4xx is only available since Apache 2.

Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • Does R=4xx work in browsers? I tried it once and couldn't get it to work, but it's *possible* I was using Apache 1.3. – ceejayoz Dec 29 '09 at 18:11
  • @ceejayoz: Everything is done internally on the server side. The client just gets the response. – Gumbo Dec 29 '09 at 18:26
  • If, like me, the R=410 gives an Apache error, try redirecting to a PHP script with – Liam Nov 14 '11 at 13:29
4

You can simply use an .htaccess file like this:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_URI} !.*index\.php
   RewriteRule (.*) /index.php
</IfModule>
Candy
  • 41
  • 1
1

This is much simpler:

RedirectMatch temp .* http://www.newdomain.com/newdestination.html

It redirects every single request to newdestination.html.

Note that if you point to the same domain as the source, there will be an infinite loop and this will fail. This works great pointing to a new domain, though.

Gary Samad
  • 813
  • 7
  • 14