410 Entire Directory With .htaccess

Due to an oversight with folder permissions, I was recently the victim of a massive spam attack. I fixed the problem by issuing a 410 redirect to all links pointing to a particular folder in my file tree.

If you’re trying to force a 410 (“gone”) status code for a particular folder directly in your site’s root path (ie, /public_html/someFolder), place the following in your root .htaccess file.

RewriteEngine On
RewriteBase /
RewriteRule ^someFolder/ - [G]

Replace “someFolder” with the folder of interest. For example, if you’re trying to 410 redirect /public_html/blog, use “blog” in the code above. Then test the site by opening a browser and navigating to the folder you blocked. You should be prompted with a “Gone” error page for any page under that folder (ie, http://yourdomain.com/someFolder/, http://yourdomain.com/someFolder/page1, http://yourdomain.com/someFolder/page2, etc.)

The 410 HTTP status code basically means that a page is “gone” and should never come back. This should hopefully let major search engines index everything accordingly.

Related Articles

3 COMMENTS

  1. Will this work with query parameters? I have the same problem with spam attack but they are all “/?s=*”

  2. thank you so much
    i have any bad page indexed on google
    with 410 and robot and removels i can fix it 🙂
    thank you 😀

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Try EchoTools - my free, iOS ultrasonography reference application!

Latest Articles