Official way to make topicxx.html to topictitle.html

Discussions and support about the different URL Rewriting techniques for phpBB.

Moderator: Moderators

Official way to make topicxx.html to topictitle.html

Postby iwanttobelieve » Tue Jun 16, 2009 10:49 am

Sorry for a confusing topic title. I really want to know the official way to make a URL like article3100.html become topic-title-t3100.html for every mod we have. I have read a lot and come up with this idea, which is currently working pretty nice on my site. It works with Latest Forum Post mod and Similar Topic mod. This assumes that you have installed the No Dupe mod by phpbb-seo.

The mechanism is the same. Find the place where you are going to assign the template vars. e.g. for Similar Topic mod. Open viewtopic.php and Find:

Code: Select all
if ($auth->acl_get('f_read', $similar['forum_id']))
{


Add after:
Code: Select all
// www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
      if (@$phpbb_seo->seo_opt['no_dupe']['on']) {   
                        if ($similar['topic_status'] == ITEM_MOVED) {
            $similar['topic_id'] = $similar['topic_moved_id'];
         }      
         $phpbb_seo->prepare_iurl($similar, 'topic', $similar['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$similar['forum_id']]);
         $phpbb_seo->seo_opt['topic_forum_name'][$similar['topic_id']] = $similar['forum_name'];
         if ($auth->acl_get('m_approve', $similar['forum_id'])) {
            $similar['forum_topics'] = $similar['forum_topics_real'];
            $replies = $similar['topic_replies_real'];
         } else {
            $similar['forum_topics'] = $similar['forum_topics'];
            $replies = $similar['topic_replies'];
         }
         if (($replies + 1) > $phpbb_seo->seo_opt['topic_per_page']) {
            $phpbb_seo->seo_opt['topic_last_page'][$similar['topic_id']] = floor($replies / $phpbb_seo->seo_opt['topic_per_page']) * $phpbb_seo->seo_opt['topic_per_page'];
         }
      } else {
         $row['forum_topics'] = ($auth->acl_get('m_approve', $similar['forum_id'])) ? $similar['forum_topics_real'] : $similar['forum_topics'];
      }
// www.phpBB-SEO.com SEO TOOLKIT END -> no dupe


Then, when you assign var:

1. For topic URL:
Code: Select all
$similar_topic_url   = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=" . $similar['forum_id'] . '&t=' . $similar['topic_id']);


2. For Latest Post URL:
Code: Select all
$similar_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $similar['forum_id'] . '&t=' . $similar['topic_id'] . '&start=' . @intval($phpbb_seo->seo_opt['topic_last_page'][$similar['topic_id']]) ) . '#p' . $similar['topic_last_post_id'];


You can add the checking for No Dupe mod if you want.

You will also have to add to the $sql whichever variable you need to SELECT more, in this case, f.forum_topics_real and t.topic_replies_real are needed. In addition, the checking for moved_topic might not be needed.

This is simply what I have come up with and is not the official way to do this so we really need our admin to enlighten us in this. Like catching every possible problems, moved_topic, temporarily deleted topíc, etc.

Hope this helps and longing for admin :roll:
iwanttobelieve
PR1
PR1
 
Posts: 123
Joined: Sun Jun 14, 2009 5:37 am
Location: Somewhere I don't belong lol

Advertisement

Re: Official way to make topic"postid".html => topictitle.html

Postby dcz » Wed Jun 17, 2009 9:18 am

Nice work, but you could make this more general.

First, it's up to the mod to provide with the proper topic_id in case it is a moved one, so :
Code: Select all
      if ($similar['topic_status'] == ITEM_MOVED) {
         $similar['topic_id'] = $similar['topic_moved_id'];
      }


is not really a part of the rewriting process, but rather something that the mod should do in all cases.
Then, after this, to url rewrite all cases, you would, in your example only need this :
Code: Select all
   // www.phpBB-SEO.com SEO TOOLKIT BEGIN
   $phpbb_seo->set_url($similar['forum_name'], $similar['forum_id'], $phpbb_seo->seo_static['forum']);
$phpbb_seo->prepare_iurl($similar, 'topic', $similar['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$similar['forum_id']]);
   // www.phpBB-SEO.com SEO TOOLKIT END


Noticed that I add a call to phpbb_seo::set_url for the forum bit.

For this only, you need to make sure that the mod will SELECT all fields form the topic table, but at least topic_id, topic_type and, if the sql rewrite option is activated topic_url are required. This imply to have the forum_name available too, which requires you to select only the topic fields required (not all) if you are grabbing the forum info in the same query.
Due to the fact that forum_id is present in both topic and forum table, if you select all topic fields, you may encounter some issues, you have an example of this query in includes/functions_dispaly.php, in the display_user_activity() function :
Code: Select all
      $sql = 'SELECT t.topic_title, t.topic_type ' . (!empty($phpbb_seo->seo_opt['sql_rewrite']) ? ', t.topic_url' : '') . ', f.forum_id, f.forum_name
         FROM ' . TOPICS_TABLE . ' AS t, ' . FORUMS_TABLE . ' AS f
         WHERE t.topic_id = ' . $active_t_row['topic_id'] . '
         AND f.forum_id = t.forum_id';
      $result = $db->sql_query($sql);

We need in such case to make sure that the SQL rewriting is activated to make sure that the topic_url field was actually added to the topic table, note that the above code for rewriting will work the same with and without the sql rewriting option, with all possible options actually ;)

Then for the no dupe, wich here would only be used to compute the last topic page :
Code: Select all
   // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
   if (@$phpbb_seo->seo_opt['no_dupe']['on']) {   
      if ($auth->acl_get('m_approve', $similar['forum_id'])) {
         $similar['forum_topics'] = $similar['forum_topics_real'];
         $replies = $similar['topic_replies_real'];
      } else {
         $similar['forum_topics'] = $similar['forum_topics'];
         $replies = $similar['topic_replies'];
      }
      if (($replies + 1) > $phpbb_seo->seo_opt['topic_per_page']) {
         $phpbb_seo->seo_opt['topic_last_page'][$similar['topic_id']] = floor($replies / $phpbb_seo->seo_opt['topic_per_page']) * $phpbb_seo->seo_opt['topic_per_page'];
      }
   } else {
      $row['forum_topics'] = ($auth->acl_get('m_approve', $similar['forum_id'])) ? $similar['forum_topics_real'] : $similar['forum_topics'];
   }
   // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe


I would personally keep the original topic link untouched, and rather mod the last post link with the no dupe code you used, and the same way you did.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21398
Joined: Fri Apr 28, 2006 9:03 pm

Re: Official way to make topic"postid".html => topictitle.html

Postby iwanttobelieve » Wed Jun 17, 2009 1:59 pm

Thank you for your detailed guide, I think we should make an official method, should we? So everyone can get every URL rewritten on every page they one. I mean we can post a full script :D . I will try what you have advised and see if I need to ask more. Thanks, again!
iwanttobelieve
PR1
PR1
 
Posts: 123
Joined: Sun Jun 14, 2009 5:37 am
Location: Somewhere I don't belong lol

Re: Official way to make topic"postid".html => topictitle.html

Postby dcz » Wed Jun 17, 2009 4:32 pm

Well, you're welcome to explain things further in details if you wish, but there is not final answer, since all mods will be a bit different. But yes, the principle is always the same so, I guess that some doc about this would be very good for everybody ;)
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21398
Joined: Fri Apr 28, 2006 9:03 pm

Re: Official way to make topic"postid".html => topictitle.html

Postby dcz » Wed Jun 17, 2009 6:24 pm

Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21398
Joined: Fri Apr 28, 2006 9:03 pm

Re: Official way to make topic"postid".html => topictitle.html

Postby iwanttobelieve » Thu Jun 18, 2009 7:24 am

Yup, and could you please be the one who make that doc? hehe : P
iwanttobelieve
PR1
PR1
 
Posts: 123
Joined: Sun Jun 14, 2009 5:37 am
Location: Somewhere I don't belong lol


Return to phpBB mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 7 guests