.com.unity Forums

.com.unity Forums (http://forum.shrapnelgames.com/index.php)
-   Shrapnel General (http://forum.shrapnelgames.com/forumdisplay.php?f=14)
-   -   Automated redirect for old post/thread links (http://forum.shrapnelgames.com/showthread.php?t=40244)

Richard August 17th, 2008 05:50 PM

Re: Automated redirect for old post/thread links
 
Quote:

Originally Posted by vfb (Post 631845)
Sounds like a great feature!

But my old embedded links do not seem to be working either, eg:

http://www.shrapnelcommunity.com/thr...ev=#Post595147

Even this does not work:

http://www.shrapnelcommunity.com/thr...?Number=595147

Is it because I'm not linking to the top thread?

Okay so the problem here is the way UBB handled things. The problem is they used the same script to refer to threads and posts without an easy way to know via URI string which they were doing. So for Balbarians posts above they work because there is a reference to the thread. For your's it won't work because your referring to showflat to a post, not a threadid. Posts are supposed to use a different script name (I think it's showthreaded). I am going to on individual posts next but a direct link to a post using showflat is just going to be broken.

Ballbarian August 17th, 2008 05:55 PM

Re: Automated redirect for old post/thread links
 
Quote:

Originally Posted by Richard (Post 632037)
Okay all of these should work now. Let me know...

Great! :up:

All appear to be working now with one exception:
http://www.shrapnelcommunity.com/thr...&Number=528292

That old thread link was working with some of your changes (earlier), but now goes to the 404 page.

Richard August 17th, 2008 06:26 PM

Re: Automated redirect for old post/thread links
 
Quote:

Originally Posted by Ballbarian (Post 632046)
Great! :up:

All appear to be working now with one exception:
http://www.shrapnelcommunity.com/thr...&Number=528292

That old thread link was working with some of your changes (earlier), but now goes to the 404 page.

Okay this one may be able to be fixed but I am not sure. The problem is most incoming links have an & after the post number and the redirect is looking for that. These types of url's don't have an & at the end so it's confused :). Let me think on that one...

lch August 18th, 2008 10:26 AM

Re: Automated redirect for old post/thread links
 
Richard, thanks for looking into this. I'd recommend that you create substitutes for the old showflat.php, shownested.php etc. scripts instead of abusing 404 error pages for this.

I'll drop some PHP code here which I have been using for some projects myself. First, a replacement for PHP's parse_url function:
PHP Code:

// returns an array with the following elements defined in it:
//   scheme://username:password@host:port/path?query#fragment
// this function is more robust than parse_url

function parseUrl($url) {
  
$r  '!(?:(?<scheme>\w+)://)?(?:(?<username>\w+)\:(?<password>\w+)@)?(?<host>[^/:]+)?';
  
$r .= '(?:\:(?<port>\d*))?(?<path>[^#?]+)?(?:\?(?<query>[^#]+))?(?:#(?<fragment>.+$))?!i';
  
preg_match($r$url$out);
#  for ($i = 0; $i < 9; ++$i)
#    unset($out[$i]);
  
return $out;


then one which does the reverse:
PHP Code:

// inverse function to parseUrl

function glueUrl($parsed)
{
  if (!
is_array($parsed)) return false;
  
$uri strlen($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? '' '//') : '';
  
$uri .= strlen($parsed['user']) ? $parsed['user'].(strlen($parsed['pass']) ? ':'.$parsed['pass'] : '').'@' '';
  
$uri .= strlen($parsed['host']) ? $parsed['host'] : '';
  
$uri .= strlen($parsed['port']) ? ':'.$parsed['port'] : '';
  if (
strlen($parsed['path'])) {
    
$uri .= ($parsed['path'][0] == '/') ? $parsed['path'] : ('/'.$parsed['path']);
  }
  
$uri .= strlen($parsed['query']) ? '?'.$parsed['query'] : '';
  
$uri .= strlen($parsed['fragment']) ? '#'.$parsed['fragment'] : '';
  return 
$uri;


and finally something which uses both to merge a given URL with a query string, which shows how they can be used:
PHP Code:

// merges given URL with the specified query string

function MergeQueryStrings($url$query) {
  
$parsed parseUrl($url);
  
parse_str($query$addq);
  
parse_str($parsed['query'], $oldq);
  
$newq array_merge($oldq$addq);
  
$parsed['query'] = http_build_query($newq);
  return 
glueUrl($parsed);


Maybe it's some help. What you really should make use of is the parse_str function.

lch September 4th, 2008 04:41 AM

Re: Automated redirect for old post/thread links
 
The link redirections don't seem to work anymore. They did before - so please, get them back unless you plan to batch replace all the old links in the posts and signatures.


All times are GMT -4. The time now is 03:36 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2024, Shrapnel Games, Inc. - All Rights Reserved.