Block some pages with htaccess

I used to have php script which made dynamic pages like this.,23
and so on

the problem is that I have removed the script from my server and I have static html pages like index.html and the above pages are still works because of that ? after the first / because the server is attaching those files as,23

They are all indexed by search engines and I dont want 50 duplicate content from my index.html pages cuz all the above pages displays default html page /? <- because of that.

is there any way to show error 410 gone using htaccess?

I used RewriteRule ^index.html$ - [R=404,L,NC] and it is not working.

Then I tried RewriteRule ^/?$ - [R=410,L,NC] and it works but if I type then I get the error page and it does not open default index.html page.

Is it possible if the url contains ? then just throw a 410 page?


Your first error was in not specifying the file which was handling your query string. LAZY links like this DO cause problems (using the DirectoryIndex) and now you’re paying the price.

Assuming that you’ve deleted all the files associated with your keywords, you have several options:

  1. First, if you’re only using static webpages (.html), then simply delete all query strings with code like

    RewriteCond %{QUERY_STRING} >' ' RewriteRule .? %{REQUEST_URI}? [R=301,L]

    That will remove EVERY query string.
  2. If you have other script which require a query string, you can remove the query string on the index.html file with code like

    RewriteCond %{QUERY_STRING} >' ' RewriteRule ^index\\.html$ %{REQUEST_URI}? [R=301,L]
  3. You COULD list your keywords but why when the above will work efficiently?

As for your ErrorDocument, you have a problem because /?key=-value is specifying the DirectoryIndex and that’s what you’re providing, i.e., 404 is not correct. Since you’re providing index.html, I’d recommend that you let the visitors figure that out for themselves.



Thanks dklynn, this code is working fine.

RewriteCond %{QUERY_STRING} >''
RewriteRule .? %{REQUEST_URI}? [R=410,L]

I m now returning error 410 for all pages with

Tip: never hide the file name like index.php or you ll be having trouble with SEO. Once you delete your file they will still be indexed like