[Split]Do topic/post links auto update/change when moving post?

Discussion forum for MOD Writers regarding MOD Development.
olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

[Split]Do topic/post links auto update/change when moving post?

Post by olsserik »

Hi,
Old topic but I did not find any newer.
I think this is a big problem today, I can see in webmaster tools that some moved topics gets filed as duplicate content.

Correct way would be to add a 301 moved perm ... to the old link when moved.

Could that be done with a mod?
Last edited by Brf on Thu Sep 17, 2015 1:44 pm, edited 1 time in total.
Reason: Moved to Mod Writers Discussion
User avatar
Lumpy Burgertushie
Registered User
Posts: 69228
Joined: Mon May 02, 2005 3:11 am

Re: Do topic/post links auto update/change when moving post?

Post by Lumpy Burgertushie »

don't need a MOD if you want to use a 301 redirect. read up on how to do those.

however, regardless of what your websmaster tools say, it is simply not a problem of duplicate content for the search engines. the search engines are plenty smart enough to understand how things like phpbb work and know that sometimes these things happen.

the only kind of duplicate content that search engines care about is when you actually create duplicate web pages that different links point to trying to spam the search engines.

robert
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: Do topic/post links auto update/change when moving post?

Post by olsserik »

Hi,
Do you mean manual 301 redirects? If so, I´m not. I´m guessing there would be around 1000 redirects per year and I dont want do to that manually.

Not doing it manually I think will require some kind of modding, if not, pls tell me how to do it.
User avatar
Lumpy Burgertushie
Registered User
Posts: 69228
Joined: Mon May 02, 2005 3:11 am

Re: Do topic/post links auto update/change when moving post?

Post by Lumpy Burgertushie »

a 301 redirect by definition is automatic. you set it up in a htaccess file in the root of the board.

it is a server side thing. has nothing to do with phpbb.

you would have to search google, etc. for the proper way to write the redirect to get whatever it is you are trying to do.

like I said, this is way too much trouble if "duplicate content" is all you are worried about.

your choice.

robert
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: Do topic/post links auto update/change when moving post?

Post by olsserik »

Yes, I know how to set a redirect in .htaccess.
The function

Code: Select all

Redirect
is automatic, but placing the code in the in the .htaccess I guess is not?

I disagree with you, it´s a phpbb problem.
Wordpress has it in core, I have to be honest and say I dont know if it is a real 301, but if you change a posts category and goes to the old link, it moves to the new link.

Furthermore I dont now the best logic here, but i´m guessing you have to save a category history in DB and call that history to see if there is a match in viewtopic, if so, redirect with php.
So, in my world this has nothing to do with editing on .htaccess, it should be handled in viewtopic.php by php.
User avatar
Oyabun1
Former Team Member
Posts: 23162
Joined: Sun May 17, 2009 1:05 pm
Location: Australia
Name: Bill

Re: Do topic/post links auto update/change when moving post?

Post by Oyabun1 »

phpBB 3.1 has canonical links for pages such as viewtopic.
                      Support Request Template
3.0.x: Knowledge Base Styles Support MOD Requests
3.1.x: Knowledge BaseStyles SupportExtension Requests
olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: Do topic/post links auto update/change when moving post?

Post by olsserik »

Sorry for a late reply.
I run 3.0.13 and have added correct Canonical support for viewtopic.php.
This summer I made some research on keywords and topics for my forum. I compared an earlier moved topic with an topic I added 301 redirect for. In my opinion there was a change in ranking and I think vanilla phpbb gets punished by Google if a topic is moved to another category due to duplicate content, e.g:

http://example.com/viewtopic.php?f=1&t=2

gets moved to

http://example.com/viewtopic.php?f=2&t=2

Both links above shows the same content and the problem is that the first url should be (in my opinion) 301 Redirected to url 2.

I think I managed to fix this and Im posting to code below. I take no responsibility for this and use at own risk!
If someone with knowledge sees anything wrong with it, please post an update or comment.

In viewtopic.php, find (around line 30):

Code: Select all

$start		= request_var('start', 0);
After add:

Code: Select all

// We must fetch current forum_id to check differences and to inject correct
//$forum_id if missing. Also added cache after comments from Amigojack
$sql = 'SELECT forum_id
		FROM ' . TOPICS_TABLE . "
		WHERE topic_id = $topic_id";
	$result = $db->sql_query($sql, 86400);
	$correct_f = (int) $db->sql_fetchfield('forum_id');
// #1 Redirect, if parameter "f" missing, add it and 301 permanent
if ($topic_id && !$forum_id){
	$viewtopic_build_url = 'f=' . $correct_f . '&t=' . $topic_id;
	if ($topic_id && $start){
		$viewtopic_build_url = 'f=' . $correct_f . '&t=' . $topic_id . '&start=' . $start;
		}
		$vt_new_furl = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $viewtopic_build_url);
		$vt_new_furl = str_replace('&', '&', $vt_new_furl);
			header("HTTP/1.1 301 Moved Permanently");
			header("Location:" . $vt_new_furl);
			header("Connection: close");
}
// End of #1, start of second redirect, if topic where moved, assign correct forum_id and 301 permanent
			if ($forum_id !== $correct_f) {
			$correct_string_url = 'f=' . $correct_f . '&t=' . $topic_id;
			if ($topic_id && $start){
			$correct_string_url = 'f=' . $correct_f . '&t=' . $topic_id . '&start=' . $start;
			}
	$new_301 = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $correct_string_url);
	$new_301 = str_replace('&', '&', $new_301);
		header("HTTP/1.1 301 Moved Permanently");
		header("Location:" . $new_301);
		header("Connection: close");
}
//Redirect #2 end
This snippet will:

1. Redirect all incoming urls not containing "f", forum_id to correct url (injecting "f=x" in url).
2. Check if incoming url contains faulty forum_id (if topic has been moved) and if so, assign correct forum_id and redirect.

Edit: Changed the code after AmigoJacks comments.
Last edited by olsserik on Thu Sep 17, 2015 1:32 pm, edited 2 times in total.
User avatar
AmigoJack
Registered User
Posts: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

Re: Do topic/post links auto update/change when moving post?

Post by AmigoJack »

Congratulations: you
  1. increased the database load without thinking of a cache or how to optimizing it a bit,
  2. will loop redirects on global topics,
  3. won't have a redirect fallback for servers not supporting it (see function redirect()),
  4. won't act on posts (just on topics) as input,
  5. created redundant code: why not executing the very same SELECT at the beginning?
You repeated your mistakes instead of learning from them.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: Do topic/post links auto update/change when moving post?

Post by olsserik »

AmigoJack wrote:Congratulations: you
  1. increased the database load without thinking of a cache or how to optimizing it a bit,
  2. will loop redirects on global topics,
  3. won't have a redirect fallback for servers not supporting it (see function redirect()),
  4. won't act on posts (just on topics) as input,
  5. created redundant code: why not executing the very same SELECT at the beginning?
olsserik wrote:If someone with knowledge sees anything wrong with it, please post an update or comment.
Would you like to help or only be cheeky?
User avatar
AmigoJack
Registered User
Posts: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

Re: Do topic/post links auto update/change when moving post?

Post by AmigoJack »

I commented. I also linked to a previous post of you making the same mistakes. Which leaves me uninformed on which things you need help. Ask specific questions and I will answer them (in case you forgot), but I won't do the full job of coding it all - that'd be outsourcing, not helping.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: Do topic/post links auto update/change when moving post?

Post by olsserik »

Ok, fair, lets try again! ;)
I´ve edited to code above after reading your comments.
Not sure what would be reasonable cache time for this, just placed a number to check. Suggestions are appr.
Also moved up the sql statement so if the url is without "f=x" parameter, only one statement are processed.

But I can not make it loop with a global topic, when would this apply?

Sorry, I only know LAMP servers so I can not edit the code to work on others.

It wont act on post input. But I dont think that is a big issue because when a topic is viewed via post parameters the canonical rel seems to perform better (in Google Search Console, duplicates) so Im not so concerned about that. There seems to be an issue though with same $forum_id parameter.
User avatar
AmigoJack
Registered User
Posts: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

Re: Do topic/post links auto update/change when moving post?

Post by AmigoJack »

olsserik wrote:But I can not make it loop with a global topic, when would this apply?
With global topics (User guide 5.4.4.1: Topic Types > Global), those forum IDs are 0, hence your code if ($topic_id && !$forum_id){ will evaluate to TRUE for each request.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
Lumpy Burgertushie
Registered User
Posts: 69228
Joined: Mon May 02, 2005 3:11 am

Re: [Split]Do topic/post links auto update/change when moving post?

Post by Lumpy Burgertushie »

and once again, I say that it is all a waste of time. google does not care about this as far as duplicate content goes.

if you saw any reduction in "ranking" then it was simply because the new link takes some time to be indexed properly, not because it is "duplicate content". If this was a problem don't you think it would be very wide spread considering how many hundreds of thousands of phpbb board are out there and how many times posts get moved etc?


luck,
robert
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: Do topic/post links auto update/change when moving post?

Post by olsserik »

AmigoJack wrote:
olsserik wrote:But I can not make it loop with a global topic, when would this apply?
With global topics (User guide 5.4.4.1: Topic Types > Global), those forum IDs are 0, hence your code if ($topic_id && !$forum_id){ will evaluate to TRUE for each request.
Thanks.
The link above does not work for me.
I guess the simplest is to wrap the whole code in an

Code: Select all

if ($forum_id !== 0)
Or is there any predefined check that can be done without going to the db and ask if it´s global?

@robert:
Do you have evidence for your statement?
During the past three months I´ve made som research about this and I think there is a difference.

But I think we can discuss seo to the end of time so let´s not.

There are one other things though, not only regarding seo:
I would rather stick with the $forum_id parameter in viewtopic, I think it has a purpose. But in vanilla phpbb it does not seem to have a purpose. You can use whatever number you want, it´s useless in viewtopic.php. But if you can validate it I think there are a good thing having it, it creates structure even though its not "readable" for users.

Actually this applies somehow to the "start" parameter as well.
Example in viewforum. If I put in random number in the start parameter in the url it renders out the forum and pagination based on that.

viewforum.php?f=46&start=11
viewforum.php?f=46&start=14
viewforum.php?f=46&start=36
viewforum.php?f=46&start=47
viewforum.php?f=46&start=66
viewforum.php?f=46&start=96

If Google sees these links above I guarantee that the forum will show up as duplicate content in your GSC.

Or am I wrong?
User avatar
AmigoJack
Registered User
Posts: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

Re: Do topic/post links auto update/change when moving post?

Post by AmigoJack »

olsserik wrote:The link above does not work for me.
First of all: it "works", since you're getting a page. Please stop being this imprecise. Second: it's phpbb.com's stupid JavaScript that modifies the outcome of that URI - disable JavaScript and the site loads as it should. I created WEBSITE-1245 for this bug.
olsserik wrote:I guess the simplest is to wrap the whole code in an
Then half of your code would never be executed. You wanted to add missing forum IDs - did you forget that already?
olsserik wrote:any predefined check
So you never found if (!$forum_id) in the original code of that file, hence never considered moving your code? Plus the constant POST_GLOBAL seems also new to you?
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28

Return to “[3.0.x] MOD Writers Discussion”