Page 1 of 1

Repair links to the old forum automatically - REFERENCE

Posted: Sat Apr 17, 2010 7:43 am
by tchon
I just discovered that repairing the links in the old posts in the form is actually much simpler than I have expected. Actually the ids of the threads and the posts seem to remain the same, its just the file name that has changed.

If a link to an old thread has the form:
/modules.php?name=Forums&file=viewtopic&t=<number>
then a working new link can be constructed as:
/forum/viewtopic.php?t=<number>
(the new software automatically figures out the right forum number).
Similar a link to a certain post looks like:
/modules.php?name=Forums&file=viewtopic&p=<number>#<number>
To repair the anchor, one has to pass the "p" both as "p" and "e"; this looks like:
/forum/viewtopic.php?p=<number>&e=<number>
So to make all links working, one more or less needs to replace the /modules.php by /forum/viewtopic.php in the URL to keep things running.

This can be done at the server side via a small configuration change. Just do the following:
1. enable mod_rewrite if not already done so, e.g. by adding a line like

Code: Select all

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
to the server config.
(the path to the mod_rewrite.so might need to adapted to the actual directory layout on the server.)
2. Add the following lines to the config

Code: Select all

        RewriteEngine On
        RewriteLog /var/log/apache2/rewrite_dollform.log
        # for debugging
        #RewriteLogLevel 9
        # for production
        RewriteLogLevel 0

        RewriteCond %{QUERY_STRING} ^(.*&)?p=([0-9]+)(.*)
        RewriteRule ^/modules.php$ /forum/viewtopic.php?%1p=%2&e=%2%3 [R]
        
        RewriteCond %{QUERY_STRING} ^(.*&)?t=([0-9]+)(.*)
        RewriteRule ^/modules.php$ /forum/viewtopic.php?%1t=%2%3 [R]
(again the path to the log file needs to be adapted, of maybe even the RewriteLog directive left out completely)
3. reload the server config
Ready.

I have tested the performance impact on a local test server, and while my local server needs 0.4ms to send the 404-error page it needs quite the same time to send the redirect. Only if one sends very long malicious urls the server needs somewhat around 1.2ms to handle the request. I hope this performance increase is acceptable. (After all a normal page view needs around 500ms or so.)

If the server admins would consider this change, this would be highly appreciated, at least by me :)

Meanwhile all members who run into a 404 for an old link on the forum can just repair it by replacing "/modules.php" by "/forum/viewtopic.php" in the URL manually to see the post in the new forum.

Re: Feature Request: Repair links to the old forum automatically

Posted: Sun Apr 25, 2010 5:12 am
by TDF_Management
Thanks, Tchon.

We have been considering running a search and replace within the database itself to do all the fixes in a few passes.

This could prove useful.

Re: Feature Request: Repair links to the old forum automatically

Posted: Sun Apr 25, 2010 12:10 pm
by tchon
Ah, ok, a change of all links in the database is possible, too, of course.
I thought this would be too tricky and/or dangerous to do it, but of course this would solve the problem permanently. The rewrite rules in the server would be less invasive, but will only postpone the problem somewhat.
Thanks for considering the issue in any case, I at least very appreciate it.

Re: Feature Request: Repair links to the old forum automatically

Posted: Sun Apr 25, 2010 1:55 pm
by siliventurer
tchon wrote:Ah, ok, a change of all links in the database is possible, too, of course.
I thought this would be too tricky and/or dangerous to do it, but of course this would solve the problem permanently. The rewrite rules in the server would be less invasive, but will only postpone the problem somewhat.
Thanks for considering the issue in any case, I at least very appreciate it.
tchon, it is indeed tricky/dangerous to attempt that. The rewrite could be another possibility and we'll look into it. However, I think the best approach temporarily is for people to use the 'Report Post' button to flag any broken link messages so that we can go in and fix them. This is also permanently fixing the problem bit by bit.

Re: Feature Request: Repair links to the old forum automatically

Posted: Mon Apr 26, 2010 12:39 am
by TangoUniform
From an operative point of view it would make sense implementing a redirect. Fixing old posts on the forum is fine, but what about external links to the forum? You can only fix those with a redirect, unless you want to contact dozens, maybe hundreds of people and tell them to fix their links.

Repair bookmarklet for the impatient

Posted: Fri Apr 30, 2010 5:00 pm
by tchon
While the forum management decides which way to repair links is the best, I come up with an intermediate solution for the impatient (like me) so they don't have to bug management. ;)
The workaround is to add a special bookmark/favourite to the browser; everybody can do this on their own.
Everytime one gets to a 404 error for some old forum link, one can select this bookmark and it forwards to the repaired url.

On firefox it works as follows:
  • open the "Organize Bookmarks" window
  • select the "bookmarks toolbar" (or any other place where You can add bookmarks
  • create a new bookmark with e.g. the title "TDF link repair" and as location the rather long following text:

    Code: Select all

    javascript:if(document.location.hostname.indexOf("dollforum.com")>-1&&document.location.pathname=="/modules.php"){document.location.href=document.location.href.replace(/modules.php/,'forum/viewtopic.php').replace(/p=(\d+)/,'p=$1&e=$1')}
    (if possible, try to do this without the linebreak)
Done.
The code might look a bit cryptic but all it does is automatizing the manual replacement in the url I proposed in the original post.

I guess this should work with all other browsers, but I have only firefox on my box, so I cannot test it, sorry. Please post questions or issues about that repairing bookmark here or send me a PM.

Re: Feature Request: Repair links to the old forum automatically

Posted: Fri Apr 30, 2010 7:54 pm
by siliventurer
Just as an additional note to everyone regarding tchon's post above...

Anyone who wishes to use the above temporary scripting procedure tchon details above does so at their own risk. This is not to say that the procedure will cause any harm, but just to clarify that TDF will not be liable or responsible for any damage to a computer resulting from it's usage. We will also not provide any support for this and suggest that you contact the original poster for any support.

tchon, we are still actively working on resolving this issue and will post an update at the appropriate time. As I stated previously, if you or anyone comes across a post that has bad links, report that post using the "Report Post" button so that we can correct them permanently.

Repair bookmarklet for the impatient -Disclaimer

Posted: Sat May 01, 2010 6:53 am
by tchon
oh man, stupid me, I forgot the disclaimer. :roll:
siliventurer, you are completely right in pointing this out.

Of course that bookmarklet is to use at your own risk, and its just an idea of mine and will not be supported by TDF staff.
When I wrote "post questions here" I mean "post them here so I can read and answer them", not "post here, so the TDF staff has even more things to worry about".

I am sorry if I made the impression to press on TDF to solve this issue; just the contrary - I just wanted to post a workaround so you can take all the time it needs to solve the issue properly without any pressure.