XF 2.1 remove all thoses useless 301 redirect

aana

Active member
hello,
I saw something really not SEO friendly.

every internal links in Xenforo who point to a post are redirected because ...#

By example:

1591778772294.jpg

copy the link of the last thread who got a answer.
https://xenforo.com/community/threads/xenforo-2-1-10-patch-2-released-includes-security-fix.180901/post-1428765
this link is just a 301 redirection, the correct link is:
https://xenforo.com/community/threads/xenforo-2-1-10-patch-2-released-includes-security-fix.180901/#post-1428765

Around 70% of the internal link are a 301 redirection...
How can we correct that please ?
 

Kirby

Well-known member
Those are two completely different links:
https://xenforo.com/community/threads/xenforo-2-1-10-patch-2-released-includes-security-fix.180901/post-1428765 is a permanent link to post 1428765.
This link will always work, even if the post is moved to a different thread (in this case it will redirect to the new URL).

https://xenforo.com/community/threads/xenforo-2-1-10-patch-2-released-includes-security-fix.180901/#post-1428765 is a link to thread 180901 with an anchor for post 1428765 (which might not necssarily be in that thread).
If the post does get moved to a different thread, this link will become invalid as it still points to the original thread.

There is no way to avoid these redirects without sacrificing permanent linking to posts.
 

aana

Active member
use this link,
https://xenforo.com/community/threads/xenforo-2-1-10-patch-2-released-includes-security-fix.180901/post-1428765
he will become
https://xenforo.com/community/threads/xenforo-2-1-10-patch-2-released-includes-security-fix.180901/#post-1428765

for Google and SEO:
https://xenforo.com/community/threads/xenforo-2-1-10-patch-2-released-includes-security-fix.180901/post-1428765
301 Moved Permanently
https://xenforo.com/community/threads/xenforo-2-1-10-patch-2-released-includes-security-fix.180901/#post-1428765
200 OK
 

Kirby

Well-known member
Please re-read my post ;)

It is not possible to use thread-links with anchors instead of post links without sacrificing permanent linking to posts.

A post is part of a thread, so there is no canonical URL for a post; canonical URls can only ever exist for page as a whole and the canonocal URL for a thread is threads/<title>.<threadid>, therefor the post link does get redirected.
 

Mike

XenForo developer
Staff member
Worth noting that beyond post moving, the page number the post is on is significant. This can change over time for various reasons (like post removal, merging, etc).
 

aana

Active member
This problem is on forum list and thread list, since thoses link only show the last posted message thread, what is the problem to inclued the # ?
if a post is merged or moved or even removed, the link will change.
 

Kirby

Well-known member
As @Mike already pointed out, at those places only the postid and threadid are available - the post position (which determines the page a post is on) is not available there.
But the page is required to create a valid thread link with an anchor to the post.

This is not undoable, but would most likely require database schema changes and additional code to maintain denormalized position information in Thread and Forum entities.

Personally, I've just removed last post links from forum views for guests - IMHO they don't have much value for guests anyway.
 

aana

Active member
The postid and threadid are available.
You know that if you use: threadid /postid, the result will be a http code 301 redirection to the link threadid /#postid
You know the http code 200 pattern is : threadid /#postid
You know that if you move, merge or remove the post, the link will change.

Its not possible to add a '#' before the postid when you generate the link ?

Personally, I've just removed last post links from forum views for guests - IMHO they don't have much value for guests anyway.
+1
i am considering this option too
 
Last edited:

Kirby

Well-known member
You know the http code 200 pattern is : threadid /#postid
Please re-read my post - you need the post position to know which page a certain post belongs to

Take this link as an example: https://xenforo.com/community/threa...vements-and-dev-team-news.181244/post-1431125

It currently does get 301 redirected to https://xenforo.com/community/threa...-and-dev-team-news.181244/page-2#post-1431125

If you don't know the position/page you could only construct https://xenforo.com/community/threa...ements-and-dev-team-news.181244/#post-1431125 which does not work.
 

aana

Active member
yes but you have the post position so you can calculate the page number, or did i am wrong ?
but anyway, i am considering your option or something else who can keep internal meshing on.
Thanks.
 
Last edited:

Kirby

Well-known member
As said before, the position of the last post is not in available in the Thread or Forum Entity - you can't calculate the page without it.
So this would either require an additional (expensive) join or denormalized last post position data in Thread and Forum entities.
 

aana

Active member
Its reletead to the style you are using.
You need to find the correct page template ( its more than 1 template )

You need to check on your site, from with page/template you want to remove this link.
On thoses template find thoses kind of code
Code:
<a href="{{ link('threads/post', $thread, {'post_id': $post.post_id}) }}" class="u-concealed"
                                rel="nofollow">
                                <xf:date time="{$post.post_date}"/>

And edit this part:
{{ link('threads/post', $thread, {'post_id': $post.post_id}) }}


to remove the 'post', and the related
{{ link('threads', $thread) }}

Don't forget to do this only for visitors
 

aana

Active member
don't forget to use the Template modifications system and to test it before. I just gave you an example and for some template you may need to understand the code by yourself to adapt it.
 
Top