How do i set a 410 status for any page with a .html file extension?

779 views Asked by At

I had a site which became a victim of some spam hacks. This is all resolved, I am now just trying to set a 410 status for these pages which are part of Google's index. They 404 right now but I want them gone as quick as can be. Thankfully they all used .html and I have no other .html pages in my directory.

How can I use .htaccess to set a 410 to fit the below pattern?

http://domain.com/AnyFileName.html

This should not target anything in a subdirectory, so the below would be ignored:

http://domain.com/folder/AnyFileName.html

Below is what I have tried, but it's still returning a 404.

<IfModule mod_rewrite.c>
    RewriteRule \.html$ - [G]
</IfModule>
1

There are 1 answers

7
anubhava On BEST ANSWER

You can use:

RewriteEngine On

RewriteRule ^[^/.]+\.html$ - [G,NC,L]

[^/.]+ will make sure to match these html files only in site root leaving html files in sub directories untouched.