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/?(.*)
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)
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]
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
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.
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”)