12

I had a folder called blog on my site. I deleted it all permanently. I would like to 410 it. How do i 410 an entire folder?

e.g. my site looked like this

example.com/blog/mycoolpost1/
example.com/blog/mycoolpost2/
example.com/blog/mycoolpost3/
example.com/blog/mycoolpost4/

now posts 1,2,3,4, are dead.

so how do i specify that everything after blog, is permanently deleted. (as well as the folder 'blog' itself)

I need a htaccess line something like this...?

redirect 410 /blog/?(.*)

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Bobby Smith
  • 131
  • 1
  • 1
  • 5

5 Answers5

12

The Redirect directive is the proper way to do this. You should put the following in your virtual host configuration:

Redirect 410 /blog

If you don't have access to the virtual host configuration, you can put it in the .htaccess file in your document root, or I believe you can put the following in the .htaccess file in the blog subdirectory:

Redirect 410 /

(I might be off about that, I'm not sure how exactly Redirect interacts with path resolution in .htaccess files)

David Z
  • 128,184
  • 27
  • 255
  • 279
11

I don't think Redirect is the right tool for this, as it only matches the path specified. Just use:

RewriteEngine On
RewriteBase /
RewriteRule ^blog/ - [G]
Gerben
  • 16,747
  • 6
  • 37
  • 56
5

The following .htaccess would be useful when, for example, you move from a hosting to another and you reorder or delete parts of your web.

As Apache allows human syntax codes I have used permanent instead of 301 code, and gone instead of 410. You can check http protocol codes here Status Code Definitions

I placed the file on my root mynewblogaddress.com folder:

.htaccess

Redirect permanent /wordpress http://www.mynewblogaddress.com/blog/
Redirect gone /gallery2   
Redirect permanent /directory2 http://directory2.mynewblogaddress.com
kikeenrique
  • 2,589
  • 2
  • 25
  • 46
0

For those who are using IIS (7 or above) and stumble across this post as i did, this is how I wound up doing it using the global.asax:

void Application_BeginRequest(object sender, EventArgs e)
{
    HttpApplication app = sender as HttpApplication;

    if (app.Request.Url.PathAndQuery.IndexOf("/mydirectory") > -1)
    {
        Response.StatusCode = 410; Response.End();
    }
}

I happened to be looking for all pages in a directory, but I could have done something similar like targeting all html pages (assuming 410’ing ALL html pages were to be “gone”)

puddleglum
  • 1,020
  • 14
  • 19
0

You can set a rewrite rule in .htaccess to redirect all URLs containing the dead folder "blog" to a custom "Does not exist" error page or whatever. If you want the actual code then I would recommend reading guide-url-rewriting to help you figure this out.

Aman
  • 548
  • 1
  • 4
  • 11
  • right but i cant find the correct line. something like this, but this isnt workign: redirect 410 /blog/?(.*) – Bobby Smith Dec 18 '11 at 01:33
  • I would just use something like this: RewriteRule ^blog/(.)*$ error.php [NC,L]. It may not be the exact syntax since its been quite some time since i have used Rewriting, but something like this should work. – Aman Dec 18 '11 at 01:42