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

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

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?

3

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.

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.

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

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");

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.

Re: SEF URL redirect?

I found a better solution. All you need is an extension with the following hooks:

1) Hook vf_modify_forum_info

$seo_url = forum_sublink($forum_url['forum'], $forum_url['page'], (isset($_GET['p']) ? $_GET['p'] : 1), array($id, sef_friendly($cur_forum['forum_name'])));
if ($seo_url !== get_current_url())
    header('Location:'.$seo_url, true, 301);

2) Hook vt_modify_topic_info

$seo_url = forum_sublink($forum_url['topic'], $forum_url['page'], (isset($_GET['p']) ? $_GET['p'] : 1), array($id, sef_friendly($cur_topic['subject'])));
if ($seo_url !== get_current_url() && !$pid)
    header('Location:'.$seo_url, true, 301);

This method is better because:

1) You don't have to hack into punbb code.

2) It prevend duplicate content better, for ex. the following urls (in my website):
http://diendan.sile.vn/viewforum.php?id=36
http://diendan.sile.vn/forum/36
http://diendan.sile.vn/forum/36/abc
http://diendan.sile.vn/forum36-some-stu … words.html
....
all redirect to http://diendan.sile.vn/forum36-thu-thua … en-tu.html

Note that if you use fancy url scheme, you can cause duplicate contents when you rename your forum name or post title (for ex, http://diendan.sile.vn/forum36-some-stu … words.html and http://diendan.sile.vn/forum36-thu-thua … en-tu.html above). Using above hooks, only newest url is allowed, others will redirect to this url.

Hope it can help smile

11

Re: SEF URL redirect?

Thank you all for this discussion !

I have another idea/question : do you think it would be possible to make an URL rewriting at the level of POSTS (not only on topic and forum) with th ID of the post replaced by a small POST URL that would replace the current "http://punbb.informer.com/forums/post/132999/#p132999" URL of posts --> This URL would be 7 first word of the post for instance (or another rule if there could be some better SEO solution - such as enabling people to give a title to their posts).

What you think about that ? Is it technically possible ?

Thank you !

I think that would create title to posts, and have a blattant SEO effect !