Mobile app version of vmapp.org
Login or Join
Ogunnowo487

: What rewrite rule would show the 410 (gone) status for removed forum URLs? I have removed a forum system from my CMS and now I want to return an 410 status code whenever a search engine

@Ogunnowo487

Posted in: #410Gone #ModRewrite #QueryString #UrlRewriting

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.

The base URLs 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

Taking that into account, these are a couple of examples of the code I have added to my .htaccess:

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

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


I don't know that I am doing wrong, but the HTTP headers of these forum posts show a '404 Not Found message' instead of a 410 error.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Ogunnowo487

2 Comments

Sorted by latest first Latest Oldest Best

 

@Angela700

Based on the sample URL's you provided, its good to use these lines at the top of your .htaccess file in the document root folder (where index.html normally is located):

RewriteEngine On
RewriteRule ^forum-view(.*)$ - [NC,R=410,L]


That way, all links starting with forum-view regardless of whether the word is upper or lower case or a mix of casing will be redirected to the gone status (That's what R=410 means). Also, L is included to indicate rule processing ends there if there's a match to prevent further rules later on from messing things up. The .* means any or more characters and I enclosed it in paranthesis for simplicity.

10% popularity Vote Up Vote Down


 

@Heady270

%{QUERY_STRING} referrs to everything after the ? in the URL. Your URL doesn't have a question mark, so it isn't matching it.

You just want to make sure the that the URL contains forum-viewtopic or forum-viewforum to return 410 gone status. This single rule should do it:

RewriteRule forum-viewtopic|forum-viewforum - [G]


Another option that would be even simpler:

RewriteRule forum-view - [G]


Or maybe you want it to say "anything that starts with 'forum'":

RewriteRule ^forum - [G]


You could also use mod_alias's RedirectMatch directive rather than using mod_rewrite:

RedirectMatch gone /forum.*

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme