Prevent duplicate indexing while moving threads in phpBB


Moving a thread from one forum to another cause duplicate indexing issues in phpBB3. In such cases, both the old URL and the new URL return a “200 Found” header response, even though the thread doesn’t exist in the old forum. Ideally, the old URL should 301 redirect to the new URL. In this post we’ll learn how to do this.

phpBB uses query strings like f=X&t=Y to determine which thread to serve, where ‘X’ is the forum id and ‘Y’ is the thread id. In a “view topic” URL, the f=X part of the query string serves no purpose except to note which forum the user is browsing and accordingly reflect it in the “Who is online” page. In fact, threads can be accessed using any ‘f=X’ value, even using non-existant forum ids. This isn’t much of a problem in normal situation, as the threads are linked using their corresponding forum ids, but the duplicate indexing problem arises when a thread(s) is moved from on forum to another.

Since we need to change query strings here, neither Redirect nor RedirectMatch will work as they don’t take query strings into account. We need to use RedirectCond using QUERY_STRING and a RewriteRule directive to externally rewrite the URL. We will will also send a “301 Permanently Moved” response header so that the spiders know the page has been moved. Let us suppose that a thread with thread id 5 is being moved from forum with forum id 1 to forum with id 2. Therefore, the old URL :
[text]http://domain.com/viewtopic.php?f=1&t=5[/text]
And the new URL :
[text]http://domain.com/viewtopic.php?f=2&t=5[/text]
We need to redirect the first URL to the second. Add these codes to your .htaccess file :
[text]RewriteEngine On # Skip this if you have already turned on the rewriting engine
RewriteCond %{QUERY_STRING} ^f=1&t=5$
RewriteRule ^viewtopic.php$ /viewtopic.php?f=2&t=5 [R=301,L]

RewriteCond %{QUERY_STRING} ^f=1&t=5&start=([0-9]*)$
RewriteRule ^viewtopic.php$ /viewtopic.php?f=2&t=5&start=%1 [R=301,L][/text]
Skip the first line if you have already turned on the rewriting engine in your .htaccess file. The second RewriteRule redirects the other pages of the thread (with URL like viewtopic.php?f=X&t=Y&start=10). For each thread moved, we need to add these directives in the .htaccess file, changing the forum ids and topic id’s as necessary.

This method seems tedious and cumbersome, but this is the only method I could devise as of now. If anyone has a better method, you are welcome to leave a comment.