How can I redirect everything but the index as 410?
Our site shut down and we need to give a 410 redirect to the users. We have a small one-page replacement site set up in the same domain and a custom 410 error page. We'd like to have it so that all page views are responded with 410 and redirected to the error page, except for the front page, which should point to the new index.html
.
Here's what in the .htaccess:
RewriteEngine on
RewriteCond %REQUEST_FILENAME !-f
RewriteRule !^index.html$ index.html [L,R=410]
This works, except for one thing: If I type the domain name, I get the 410 page.
With www.example.com/index.html
I see the index page as I should, but just www.example.com
gets 410. How could I fix this?
If I follow what you're trying to do, I think this would work.
RewriteEngine on
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule .* - [L,G]
If the resource doesn't exist (is not either a file or a directory) send the 410.
Create a page called maintenance.html
(or whatever file extension necessary for your server side language of choice) and then use this code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %REQUEST_URI !/maintenance.html$ [NC]
RewriteCond %REQUEST_URI !.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=410,L]
</IfModule>
This will always show maintenance.html
regardless of which page they request in their browser.
Comments
Post a Comment