1

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>
Robert E
  • 700
  • 3
  • 16
  • 29

1 Answers1

1

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.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Since the OP's code didn't work, why should this be any different (assuming that the RewriteEngine is set correctly)? – Anonymous Jun 18 '15 at 17:17
  • This is tested and working on my Apache. Do you find anything wrong in this? – anubhava Jun 18 '15 at 17:18
  • No, I was just asking if there was a reason that this should work *instead* of the OP's code. I believe both should work, but I could be wrong. – Anonymous Jun 18 '15 at 17:19
  • Well OP's code matches all html files not just in site root as OP wants. – anubhava Jun 18 '15 at 17:20
  • Right, but according to the question, the `.html` files return 404 meaning the rule was not matching the path originally or it was being overridden. – Anonymous Jun 18 '15 at 17:21
  • There can be many reasons for that but I will not speculate rather than verifying the rule on a running Apache. – anubhava Jun 18 '15 at 17:22
  • 1
    Hmm, this works. I don't know why my original solution was not working. I've tested this .htaccess code and it works exactly as what i was looking for. – Robert E Jun 18 '15 at 17:26