Forum Moderators: phranque
RewriteEngine on
RewriteRule ^(.*) /main.html
"(.*)" matches any file that someone tries to access on your server and displays the main.html file instead.
This does not change the url.
You will have to append a [R] flag or something to make it actually redirect the url I think (so it shows /main.html in the Location bar).
Can't find what flag it is at the moment, it's in the documentation or someone else will know for sure.
Jim
ErrorDocument 410 /path-to-410-error-document.html
#
RewriteRule !^path-to-410-error-document\.html$ - [G]
If you wish to add the requirement that the request is referred from google search, then add a RewriteCond:
ErrorDocument 410 /path-to-410-error-document.html
#
RewriteCond %{HTTP_REFERER} ^http://www\.google\.
RewriteRule !^path-to-410-error-document\.html$ - [G]
Want those URLs out of Google's index as well?
ErrorDocument 410 /path-to-410-error-document.html
#
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/5\.0\ \(compatible;\ Googlebot/
RewriteCond %{HTTP_REFERER} ^http://www\.google\.
RewriteRule !^path-to-410-error-document\.html$ - [G]
Jim
If you only have few images to include, or they are using the same prefix, or you put them in a special directory, then you only need to adjust the RewriteRule as follows (respond with Gone to everything except path-to-410-error-document.html and anything from the path_to_images directory):
RewriteRule
!^(path-to-410-error-document\.html)¦(path_to_images/.+)$ - [G,L]
or (respond with Gone to everything except path-to-410-error-document.html and any of those files in the path_to_images directory which starts with gone_images_):
RewriteRule
!^(path-to-410-error-document\.html)¦(path_to_images/gone_images_.+)$ - [G,L]
If this looks a bit complicated, or you have many files which does not have the same prefix, or they are in different directories, then you will need to use some RewriteCond's:
RewriteCond %{REQUEST_URI} !^/path-to-410-error-document\.html$ [NC]
RewriteCond %{REQUEST_URI}
!^/images/image_header\.jpg$ [NC]
RewriteCond %{REQUEST_URI}
!^/branding/logo\.jpg$ [NC]
RewriteCond %{REQUEST_URI}
!^/images/sorry_we_are_gone\.jpg$ [NC]
RewriteRule .* - [G,L]
And there's one more way (not counting of the use of the RewriteMap approach), use RewriteRules to stop processing more rules, so you first check the existing resources, but then you deny everything else. This might work a bit faster than the one above.
RewriteRule $path-to-410-error-document\.html$ - [NC,L]
RewriteRule ^images/image_header\.jpg$ - [NC,L]
RewriteRule ^branding/logo\.jpg$ - [NC,L]
RewriteRule ^images/sorry_we_are_gone\.jpg$ - [NC,L]
RewriteRule .* - [G,L]
This might look odd, but all what it says, if the requested resource is for example the path-to-410-error-document.html file, then do nothing, and stop processing more rules. If none of the first four rules do match, then the last rule will match anyway, so the response will be "Gone" again (so your explanation page will be displayed).
And a very last suggestion: Prefix your files with "website_is_gone_" (for example), then the original suggestion of Jim will work, only need to change the RewriteRule to (respond with "Gone" to all request where the url is not www.example.com/website_is_gone_anything or www.example.com/any_directory/website_is_gone_anything):
RewriteRule
!(^¦/)website_is_gone_.+$ - [G]
These are all alternatives, so don't try to use them all at once, choose the one you like, or fits into your situation better, and go for that one. :-)
[note]You will need to change the broken pipe (¦) characters with the solid ones before using any of the rules above, otherwise you will get errors from your Apache box.[/note]