Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess to Redirect All Traffic to One Page (410 Gone)

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?

like image 621
Ben Dyer Avatar asked Dec 07 '22 04:12

Ben Dyer


1 Answers

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.

like image 179
Gumbo Avatar answered Jan 21 '23 10:01

Gumbo