Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
Thanks, this does exactly what I want. Hmm, I'm fairly sure I tried something like this at some point, with wrong results, but perhaps there was something that wasn't quite right. –  Mikko Saari Mar 16 '11 at 7:59

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.

share|improve this answer
    
Thanks, but this doesn't change the situation: I get the 410 error page for everything but going directly to the maintenance.html. When I check the headers the site sends, there's "Location" that points to the maintenance.html file, but the 410 error page shows up (I have "ErrorDocument 410 /410.html" set in the .htaccess). Which is not a problem - I do want to see the 410 error page for everything. I just want the domain name without any file name specified to show me the index.html (or maintenance.html in your example). –  Mikko Saari Mar 15 '11 at 12:32
    
I re-read your question and saw my solution lacks the redirect on the home page. Perhaps you should show the error page to everybody and then have that page redirect to the new site after 10 seconds? That way everybody is aware of the change and redirected to the new site. Doing that would be as simple as adding a header to the error page and you're all set. –  John Conde Mar 15 '11 at 13:07
    
what's the rule to redirect the domain name on its own? !/$ possibly? That might do it. –  paulmorriss Mar 15 '11 at 16:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.