• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.5 Post permalinks broken after page shift

PJK

Active member
#1
A user mentioned this issue, and wondering what the best way to solve it is:
The permalink contain a page number. Imagine if the person A posts to the thread 20 times, then the person B will post, copy the permalink to his newest post and save it. The link will look like: "https://www.domain.com/forum/threads/somethread.x/page-y#post-z".
After a little while, a person A decides to delete all his 20 posts. The person's B post will then be on the page (y-1), so when someone opens a permalink, it will lead him to the next page from where the person's B post is now.

Here is what I did:
On the page https://www.domain.com/forum/threads/thread-title-thread.3582/page-767, the first post was by member Joe . I clicked on the post number to get a permalink, and here is what it looked like:
https://www.domain.com/forum/thread-title-thread.3582/page-767#post-1158303
I opened this link in a new incognito window of the browser to see if it works. It opened page 767 of the thread, then the page loaded, then it scrolled to Joe's post, as expected.
Then I opened the previous page (766) and deleted my old post. I reloaded the page 766 and saw Joes's post there, on the last position, as expected (because of the shift). Here comes the interesting part:
I copied new permalink to the Joe's post, it now looks like this and is accessable now:
https://www.domain.com/forum/thread-title-thread.3582/page-766#post-1158303
Then I tried to open an old link, it opened the page 767 as before, but after loading it didn't scroll anywhere obviously because it couldn't find Joe's post on this page anymore. The old permalink became broken.

I suggest using the following format for all permalinks:
https://www.domain.com/forum/posts/530335
What's the best way to prevent permalinks from breaking as described above, and change all the permalinks when copied from the post numbers to the format /forum/posts/xxxx?

Thanks.
 

Xon

Well-known member
#3
This is by design, XenForo post "permalinks" are thread relative and will change if you delete posts earlier in the thread
 

PJK

Active member
#4
This is by design, XenForo post "permalinks" are thread relative and will change if you delete posts earlier in the thread
Are you sure? It's hardly a permalink then. How can I resolve this issue to prevent this from happening? Thanks.
 

Mike

XenForo developer
Staff member
#6
You would need to edit the template post to change the "permalink" instances to point at the basic "posts" link, though note that you will then also lose any of the contextual elements in the link (notably, the thread title). It'd just be done though a link like:
Code:
{xen:link posts, $post}
 

PJK

Active member
#7
You would need to edit the template post to change the "permalink" instances to point at the basic "posts" link, though note that you will then also lose any of the contextual elements in the link (notably, the thread title). It'd just be done though a link like:
Code:
{xen:link posts, $post}
I'm unsure why these "permalinks" are built in a way where they break when posts are removed at a later time. It doesn't make sense. Can you explain this logic?

I'm more concerned at preserving working links instead of keeping contextual elements. Ideally I'd like to offer both options. Thanks.
 

Mike

XenForo developer
Staff member
#9
Are you having problems with the template modification? The suggested template edit would be the only way to get what you want in XF1 (short of some sort of add-on).

We have changed the approach in XF2 in an attempt to get the best of both worlds though.
 

PJK

Active member
#10
Are you having problems with the template modification? The suggested template edit would be the only way to get what you want in XF1 (short of some sort of add-on).

We have changed the approach in XF2 in an attempt to get the best of both worlds though.
I haven't made the template modification because it will change all previous URLs again and get rid of ones that are working. What do you suggest I do in this case? Not having permalinks doesn't really make sense (where the URL stops working when people delete posts) - can you explain that to me? Thanks.
 

Mike

XenForo developer
Staff member
#11
It will change the previous URLs, but it won't invalidate the ones that work. Indeed, when you click on one of those, it will redirect you to the exact URL that the default code links to.

While it is possible for the issue you're mentioning to happen, it is not something we have only seen rarely and the additional context of the thread info in the URL was something we felt was more beneficial.
 

OperaManiac

Well-known member
#12
Noticed that permalinks are finally permanent in xf2 today which is great. I personally try to link to https://forum.domain/posts/post-id in xf1.x which was not an optimal scenario.
 

PJK

Active member
#13
It will change the previous URLs, but it won't invalidate the ones that work. Indeed, when you click on one of those, it will redirect you to the exact URL that the default code links to.

While it is possible for the issue you're mentioning to happen, it is not something we have only seen rarely and the additional context of the thread info in the URL was something we felt was more beneficial.
Thanks, so in the event I want to revert back to the old format, I can without issue, correct? Cheers!
 

PJK

Active member
#15
Bingo, I'll do that. Lastly, when you say "You would need to edit the template post to change the "permalink" instances to point at the basic "posts" link,", which specifically are you referring to in the post template? Thanks.
 

Mike

XenForo developer
Staff member
#16
There are 2 references to:
Code:
{xen:link threads/post-permalink, $thread, 'post={$post}'}
that need to be changed to:
Code:
{xen:link posts, $post}
in the "post" template.
 

OperaManiac

Well-known member
#17
hah. thank you for this. this is one of the few things that really bother me about XF1.x. Made the change on my forum. remains to be seen if google spiders would now start linking to these permalinks or ignore them... 🤷‍
 
Last edited: