Forum Moderators: phranque

Message Too Old, No Replies

Returning 410 status for an entire forum

         

Rabash

12:37 pm on Nov 13, 2014 (gmt 0)

10+ Year Member



I have removed a forum system from my CMS and now I want to return an 410 status code whenever a search engine visits the former posts. I know that I have to use a number of Rewrite Rules to do the job, but I can't get them working. These are a couple of examples of what I've done:

RewriteCond %{QUERY_STRING} forum-viewtopic
RewriteRule .* - [G]


RewriteCond %{QUERY_STRING} forum-viewforum
RewriteRule .* - [G]


Do you what am I doing wrong?

Rabash

1:26 pm on Nov 13, 2014 (gmt 0)

10+ Year Member



I forgot to mention that the base URL of the forum that I have removed are like these:

Posts -> mywebsite.com/forum-viewtopic-p-xxx.html
Topics -> mywebsite.com/forum-viewtopic-t-xxx.html
Subforums -> mywebsite.com/forum-viewforum-f-xxx.html

penders

2:19 pm on Nov 13, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond %{QUERY_STRING} forum-viewforum 
RewriteRule .* - [G]


Not sure why you are checking against the QUERY_STRING, the example URLs you have posted don't contain a query string?

Something like the following should suffice:

RewriteRule ^forum-viewtopic- - [G]

Rabash

3:26 pm on Nov 13, 2014 (gmt 0)

10+ Year Member



Thanks for your answer Penders, but after applying your rule the HTTP headers of the forum still answer with a '404 Not Found message' instead of a 410 code.

penders

4:26 pm on Nov 13, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you have other rules in your .htaccess file?
Do you have a custom error document?

If you have a custom error document then you will also need to exclude this with a RewriteCond directive.

lucy24

5:55 pm on Nov 13, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You said CMS. If you're manually returning a 410, your added rules have to go before the CMS's own little piece of htaccess. And the rule has to be written to apply to the URL the user requests, not the "real" URL used by the server and/or CMS. If everything has been rewritten to use short pretty URLs, then the RewriteRule shouldn't require a condition at all. Definitely nothing about the query string, since that isn't part of the visible URL.

Rabash

8:56 pm on Nov 13, 2014 (gmt 0)

10+ Year Member



Thank you very much Penders and Lucy. Once I moved these rules to the top of my htaccess file everything started to work fine.

Just one more doubt. What should I do with the permalinks that follow this pattern in order to also return a 410 status?

mywebsite.com/?module=forum&file=viewtopic&t=4988

I've applied the rules that you explained to me but I can't make them work with this kind of URLs.

Rabash

11:37 am on Nov 14, 2014 (gmt 0)

10+ Year Member



I answer myself. For a URL like this:

mywebsite.com/?module=forum&file=viewtopic&t=4988

The proper rule to obtain a 410 status header is this one:

RewriteCond %{QUERY_STRING} module=forum
RewriteRule (.*) - [G]

lucy24

8:08 pm on Nov 14, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule (.*) - [G]

A rule in this form will work, and will not break anything, BUT it forces the server to evaluate the condition on every single request ever-- not just pages but images, stylesheets, contents of subdirectories. If the 410 applies only to requests for the root, the body of the rule (assuming htaccess or <Directory> section) should say

RewriteRule ^$ - [G] 

Rabash

9:01 pm on Nov 14, 2014 (gmt 0)

10+ Year Member



Thanks Lucy.