MyBB Community Forums

Full Version: how to change links all over the forum from current bburl to new URL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
(Excuse-me for my bad English Undecided)

I am not going to move my Forum, but simply I want only to modify these links ...

from:
http://www.domain.com/forumdisplay.php?fid=1
http://www.domain.com/forumdisplay.php?fid=2
http://www.domain.com/showthread.php?tid=1
http://www.domain.com/showthread.php?tid=2

to:
http://www.NewDomain.com/forumdisplay.php?fid=1
http://www.NewDomain.com/forumdisplay.php?fid=2
http://www.NewDomain.com/showthread.php?tid=1
http://www.NewDomain.com/showthread.php?tid=2

for custom reason I don't want to change the URL from settings .. I want to keep threads working for old domain and make change for links so any one will click for new thread or jump to forum will be moved to the new domain ...


I don't know from where I should do that ?
where is the code which responsible for building links !?

Thanks in advance
You can use htaccess for this. Add this to your .htaccess file:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} !^www\.NewDomain\.com
RewriteRule (.*) http://www.NewDomain.com/$1 [R=301,L]
Thanks for your response ...

As I mentioned before, I want to make this modification for custom reason ...
so I won't be able to use .htaccess

Do you know where is the code which responsible for this job !?
You said you didn't want to change the URL in the settings, which you will not be doing if you add that code to the .htaccess file.
Hi faviouz,
I tried this code but it caused a problem for me ..

I forgot to tell you that I am going to make links open as parent window target="_parent" because the board will run as iframe ...

I am still thinking that changing the code which building links for (forumdisplay.php?fid=xxx & showthread.php?tid=xxx) will be easy and comfortable ...

I found it but failed to do it ..


inc/functions.php

line 4520
/**
 * Build the forum link.
 *
 * @param int The forum id of the forum.
 * @param int (Optional) The page number of the forum.
 * @return string The url to the forum.
 */
function get_forum_link($fid, $page=0)
{
	if($page > 0)
	{
		$link = str_replace("{fid}", $fid, FORUM_URL_PAGED);
		$link = str_replace("{page}", $page, $link);
		return htmlspecialchars_uni($link);
	}
	else
	{
		$link = str_replace("{fid}", $fid, FORUM_URL);
		return htmlspecialchars_uni($link);
	}
}

/**
 * Build the thread link.
 *
 * @param int The thread id of the thread.
 * @param int (Optional) The page number of the thread.
 * @param string (Optional) The action we're performing (ex, lastpost, newpost, etc)
 * @return string The url to the thread.
 */
function get_thread_link($tid, $page=0, $action='')
{
	if($page > 1)
	{
		if($action)
		{
			$link = THREAD_URL_ACTION;
			$link = str_replace("{action}", $action, $link);
		}
		else
		{
			$link = THREAD_URL_PAGED;
		}
		$link = str_replace("{tid}", $tid, $link);		
		$link = str_replace("{page}", $page, $link);
		return htmlspecialchars_uni($link);
	}
	else
	{
		if($action)
		{
			$link = THREAD_URL_ACTION;
			$link = str_replace("{action}", $action, $link);
		}
		else
		{
			$link = THREAD_URL;
		}
		$link = str_replace("{tid}", $tid, $link);
		return htmlspecialchars_uni($link);
	}
}

in line 4516
I successfully did it for profile links
return "<a target="_parent" href=\"{$mybb->settings['NewUrl']}/".get_profile_link($uid)."\"{$target}{$onclick}>{$username}</a>";
Ok, in /inc/class_parser.php, find:

$link = "<a href=\"$fullurl\" target=\"_blank\">$name</a>";

Change blank to parent.
I didn't find any code similar to this in /inc/functions_post.php
Please make sure about this.

Thanks in advance
My bad, I meant the /inc/class_parser.php file. It's in line 869.