Topic: SEF URL redirect?

I recently enabled SEF URLs on all my PunBB forums but am having difficuly getting the search engines to index the new links. I have re-submitted sitemaps etc.

I think that the root of the problem lies in duplicate content. Is there some way to get:

viewtopic.php?id=21681

to redirect to:

topic/21681/sef-url-redirect/

instead of just displaying the same content?

Thanks smile

Last edited by Grant (2009-05-24 08:05:24)

http://fixpc.co.za/coolsites/button.php?u=PunBB

Re: SEF URL redirect?

Why do you think there is problem with new links? Maybe search engines don't crawl you forum again with new SEF links?

Re: SEF URL redirect?

I don't think there is a problem per se. It's just that I have had difficulties getting search engines to accept duplicate content before when I changed URLs and the solution seems to be a redirect.

http://fixpc.co.za/coolsites/button.php?u=PunBB

Re: SEF URL redirect?

Hello, I agree with Grant. I also have an old version 1.2.xxx PunBB forum and I would like to switch to PunBB 1.3.4 with rewriteable urls.

Outside I see the two urls, old and new, are present.

I would like to permanently redirect the old urls to the new. I do not know how.

Does anyone has a solution to offer?

I want to avoid duplicate content.

Re: SEF URL redirect?

Nobody kown ?

It's very important for me. This board     has 52000 posts and 4 years old. It has many external links.

Re: SEF URL redirect?

I've created an example of how to redirect all request from viewtopic.php according to SEF-url.

  • Edit "<FORUM_ROOT>/.htaccess". It should be:

# BEGIN PunBB

<IfModule mod_rewrite.c>
# MultiViews interfers with proper rewriting
Options -MultiViews

RewriteEngine On

# Uncomment and properly set the RewriteBase if the rewrite rules are not working properly
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} viewtopic.*
RewriteRule . redirect_viewtopic.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . rewrite.php [L]
</IfModule>

# END PunBB
  • Create the file "<FORUM_ROOT>/redirect_viewtopic.php" with this code:

<?php

define('FORUM_ROOT', './');
require FORUM_ROOT.'include/common.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id < 1)
    message($lang_common['Bad request']);

// Fetch some info about the topic
$query = array(
    'SELECT'    => 't.subject',
    'FROM'        => 'topics AS t',
    'JOINS'        => array(
        array(
            'INNER JOIN'    => 'forums AS f',
            'ON'            => 'f.id=t.forum_id'
        ),
        array(
            'LEFT JOIN'        => 'forum_perms AS fp',
            'ON'            => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
        )
    ),
    'WHERE'        => '(fp.read_forum IS NULL OR fp.read_forum=1) AND t.id='.$id.' AND t.moved_to IS NULL'
);
$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
if (!$forum_db->num_rows($result))
    message($lang_common['Bad request']);

list($topic_subject) = $forum_db->fetch_row($result);
header('Location: '.str_replace('&amp;', '&', forum_link($forum_url['topic'], array($id, sef_friendly($topic_subject)))));

?>

To create redirection for other forum links, you need to add corresponding RewriteCond to the "<FORUM_ROOT>/.htaccess" and add generation of the corresponding link to the file.

Re: SEF URL redirect?

Great !

But can you help me to make the same for viewforum.php ?

edit : i do this :

<?php

define('FORUM_ROOT', './');
require FORUM_ROOT.'include/common.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id < 1)
    message($lang_common['Bad request']);

// Fetch some info about the topic
$query = array(
    'SELECT'    => 't.forum_name',
    'FROM'        => 'forums AS t',
    'JOINS'        => array(
        array(
            'INNER JOIN'    => 'forums AS f',
            'ON'            => 'f.id=t.id'
        ),
        array(
            'LEFT JOIN'        => 'forum_perms AS fp',
            'ON'            => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
        )
    ),
    'WHERE'        => '(fp.read_forum IS NULL OR fp.read_forum=1) AND t.id='.$id.''
);
$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
if (!$forum_db->num_rows($result))
    message($lang_common['Bad request']);

list($topic_subject) = $forum_db->fetch_row($result);
header("HTTP/1.1 301 Moved Permanently");
header('Location: '.str_replace('&amp;', '&', forum_link($forum_url['forum'], array($id, sef_friendly($topic_subject)))));

?> 

is it good ?

ps : I just added that as well on the first script

header("HTTP/1.1 301 Moved Permanently");

Last edited by achtungbaby (2009-07-09 16:02:34)

Re: SEF URL redirect?

In this case script will look like:

<?php

define('FORUM_ROOT', './');
require FORUM_ROOT.'include/common.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id < 1)
    message($lang_common['Bad request']);

// Fetch some info about the topic
if (preg_match('~.*viewtopic.*~', $_SERVER['REQUEST_URI']))
{
    $query = array(
        'SELECT'    => 't.subject AS subject',
        'FROM'        => 'topics AS t',
        'JOINS'        => array(
            array(
                'INNER JOIN'    => 'forums AS f',
                'ON'            => 'f.id=t.forum_id'
            ),
            array(
                'LEFT JOIN'        => 'forum_perms AS fp',
                'ON'            => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
            )
        ),
        'WHERE'        => '(fp.read_forum IS NULL OR fp.read_forum=1) AND t.id='.$id.' AND t.moved_to IS NULL'
    );
    $page = 'viewtopic';
}
else
{
    $query = array(
        'SELECT'    => 'f.forum_name AS subject',
        'FROM'        => 'forums AS f',
        'JOINS'        => array(
            array(
                'LEFT JOIN'        => 'forum_perms AS fp',
                'ON'            => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
            )
        ),
        'WHERE'        => '(fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$id
    );
    $page = 'viewforum';
}
$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
if (!$forum_db->num_rows($result))
    message($lang_common['Bad request']);

list($subject) = $forum_db->fetch_row($result);

if ($page == 'viewtopic')
    $redirtect_url = str_replace('&amp;', '&', forum_link($forum_url['topic'], array($id, sef_friendly($subject))));
else if ($page == 'viewforum')
    $redirtect_url = str_replace('&amp;', '&', forum_link($forum_url['forum'], array($id, sef_friendly($subject))));

header('HTTP/1.1 301 Moved Permanently');    
header('Location: '.$redirtect_url);

?>

And the file "<FORUM_ROOT>/.htaccess" will be:

# BEGIN PunBB

<IfModule mod_rewrite.c>
# MultiViews interfers with proper rewriting
Options -MultiViews

RewriteEngine On

# Uncomment and properly set the RewriteBase if the rewrite rules are not working properly
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} viewtopic.* [OR]
RewriteCond %{REQUEST_FILENAME} viewforum.*
RewriteRule . redirect_viewtopic.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . rewrite.php [L]
</IfModule>

# END PunBB

Re: SEF URL redirect?

thank you very much, I'll try to refine it.