修改PHPBB论坛URL生成规则

PHPBB论坛的默认URL地址格式,比如:http://www.saferguard.com/forum/viewforum.php?f=2
                                  http://www.saferguard.com/forum/faq.php#f0r5

这样的URL格式不利于SEO的优化。SEO小组的同事提出要更改默认格式,最终显示结果:
把/forum/viewforum.php?f=2  改成   /forum/viewforum-2.html                                 
把/forum/faq.php#f0r5   改成  /forum/faq-f0r5.html

 

在phpbbchina.com上找到一篇帖子:真正的phpbb307手写伪静态,忘了那该死的插件吧!

我按着步骤修改,有报错没有修改成功。索性认真研究了下相关的几个文件,嘿嘿,终于OK了。

 

步骤如下:

第一步:修改根目录下的.htaccess文件,定义URL的规则

在文件的结果加上:

RewriteEngine on

#phpbb重写规则
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^viewtopic-(.+)-(.+).html$ viewtopic.php?f=$1&t=$2&start=$3 [L,NC]
RewriteRule ^viewtopic-(.+)-(.+).html$ viewtopic.php?f=$1&t=$2 [L,NC]
RewriteRule ^viewtopic-(.+).html$ viewtopic.php?t=$1 [L,NC]
RewriteRule ^viewforum-(.+)-(.+).html$ viewforum.php?f=$1&start=$2 [L,NC]
RewriteRule ^viewforum-(.+).html$ viewforum.php?f=$1 [L,NC]

 

第二步:修改viewtopic.php

 1. 查找:'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
     改为:'U_VIEW_FORUM' => "./viewforum". '-' . $forum_id.'.html',

 2. 查找:$pagination = generate_pagination(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '') . (($highlight_match) ? "&hilit=$highlight" : '')), $total_posts, $config['posts_per_page'], $start);
    改为:$pagination = generate_pagination1(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '') . (($highlight_match) ? "&hilit=$highlight" : '')),"./viewtopic". '-' . $forum_id.'-'. $topic_id.'-', $total_posts, $config['posts_per_page'], $start);


第三步:修改includes/functions.php

在最后加上函数generate_pagination1,代码如下:

/*Arlinger info*/
function generate_pagination1($base_url1,$base_url, $num_items, $per_page, $start_item, $add_prevnext_text = false, $tpl_prefix = '')
{
global $template, $user;

// Make sure $per_page is a valid value
$per_page = ($per_page <= 0) ? 1 : $per_page;

$seperator = '<span class="page-sep">' . $user->lang['COMMA_SEPARATOR'] . '</span>';
$total_pages = ceil($num_items / $per_page);

if ($total_pages == 1 || !$num_items)
{
return false;
}

$on_page = floor($start_item / $per_page) + 1;
$url_delim = (strpos($base_url, '?') === false) ? '?' : ((strpos($base_url, '?') === strlen($base_url) - 1) ? '' : '&amp;');

$page_string = ($on_page == 1) ? '<strong>1</strong>' : '<a href="' . $base_url . '0.html">1</a>';

if ($total_pages > 5)
{
$start_cnt = min(max(1, $on_page - 4), $total_pages - 5);
$end_cnt = max(min($total_pages, $on_page + 4), 6);

$page_string .= ($start_cnt > 1) ? ' ... ' : $seperator;

for ($i = $start_cnt + 1; $i < $end_cnt; $i++)
{
$page_string .= ($i == $on_page) ? '<strong>' . $i . '</strong>' : '<a href="' . $base_url . "" . (($i - 1) * $per_page) . '.html">' . $i . '</a>';
if ($i < $end_cnt - 1)
{
$page_string .= $seperator;
}
}

$page_string .= ($end_cnt < $total_pages) ? ' ... ' : $seperator;
}
else
{
$page_string .= $seperator;

for ($i = 2; $i < $total_pages; $i++)
{
$page_string .= ($i == $on_page) ? '<strong>' . $i . '</strong>' : '<a href="' . $base_url . "" . (($i - 1) * $per_page) . '.html">' . $i . '</a>';
if ($i < $total_pages)
{
$page_string .= $seperator;
}
}
}

$page_string .= ($on_page == $total_pages) ? '<strong>' . $total_pages . '</strong>' : '<a href="' . $base_url . "" . (($total_pages - 1) * $per_page) . '.html">' . $total_pages . '</a>';

if ($add_prevnext_text)
{
if ($on_page != 1)
{
$page_string = '<a href="' . $base_url . "" . (($on_page - 2) * $per_page) . '.html">' . $user->lang['PREVIOUS'] . '</a>&nbsp;&nbsp;' . $page_string;
}

if ($on_page != $total_pages)
{
$page_string .= '&nbsp;&nbsp;<a href="' . $base_url . "" . ($on_page * $per_page) . '.html">' . $user->lang['NEXT'] . '</a>';
}
}

$template->assign_vars(array(
$tpl_prefix . 'BASE_URL'  => $base_url,
'A_' . $tpl_prefix . 'BASE_URL' => addslashes($base_url1),
$tpl_prefix . 'PER_PAGE'  => $per_page,

$tpl_prefix . 'PREVIOUS_PAGE' => ($on_page == 1) ? '' : $base_url . "" . (($on_page - 2) * $per_page.".html"),
$tpl_prefix . 'NEXT_PAGE'  => ($on_page == $total_pages) ? '' : $base_url . "" . ($on_page * $per_page).".html",
$tpl_prefix . 'TOTAL_PAGES'  => $total_pages,
));

return $page_string;
}

 

第四步:修改includes/functions_display.php

1. 在最后加上函数topic_generate_pagination1

/*Arlinger info*/
function topic_generate_pagination1($replies, $url)
{
global $config, $user;

// Make sure $per_page is a valid value
$per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page'];

if (($replies + 1) > $per_page)
{
$total_pages = ceil(($replies + 1) / $per_page);
$pagination = '';

$times = 1;
for ($j = 0; $j < $replies + 1; $j += $per_page)
{
$pagination .= '<a href="' . $url . '' . $j . '.html">' . $times . '</a>';
if ($times == 1 && $total_pages > 5)
{
$pagination .= ' ... ';

// Display the last three pages
$times = $total_pages - 3;
$j += ($total_pages - 4) * $per_page;
}
else if ($times < $total_pages)
{
$pagination .= '<span class="page-sep">' . $user->lang['COMMA_SEPARATOR'] . '</span>';
}
$times++;
}
}
else
{
$pagination = '';
}

return $pagination;
}


2. 查找:'U_VIEWFORUM'  => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
   改为:'U_VIEWFORUM'   => "./viewforum". '-' . $row['forum_id'].".html")

3. 查找:'link'  => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
   改为:'link'  => "./viewforum". '-' . $subforum_id.'.html',

4. 查找:$u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
   改为:$u_viewforum = "./viewforum". '-' . $row['forum_id'].'.html';

5. 查找:if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
   {
    $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
   改为:if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
   {
    $u_viewforum = "./viewforum". '-' . $row['forum_id'].'-'.$start.'.html';

6. 查找:'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))
   改为:'U_VIEW_FORUM' => "./viewforum". '-' . $parent_forum_id.'.html')

7. 查找:'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
   改为:'U_VIEW_FORUM' => "./viewforum". '-' . $forum_data['forum_id'].'.html')

8. 查找:'U_ACTIVE_FORUM'  => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
   改为:'U_ACTIVE_TOPIC'  => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),


第五步:修改viewforum.php

1. 查找:$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
   改为:$view_topic_url = "./viewtopic" . '-' . $topic_id.'.html';

2. 查找:'U_VIEW_FORUM'  => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&amp;start=$start"),
   改为:'U_VIEW_FORUM' => "./viewforum". '-' . $forum_id.'-'.$start.'.html',

3. 查找:'S_FORUM_ACTION'  => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&amp;start=$start"),
   改为:'S_FORUM_ACTION'        => "./viewforum". '-' . $forum_id.'-'.$start.'.html',

4. 查找:'PAGINATION' => generate_pagination(append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '')), $topics_count, $config['topics_per_page'], $start),
   改为:'PAGINATION' => generate_pagination1(append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '')),"./viewforum". '-' . $forum_id.'-', $topics_count, $config['topics_per_page'], $start),

5. 查找:'PAGINATION'  => topic_generate_pagination($replies, $view_topic_url),
   改为:'PAGINATION'     => topic_generate_pagination1($replies, $view_topic_url1),

 

 在此,附上结合本文生成PHP论坛的sitemap方法:http://write.blog.csdn.net/postedit/7631444

 

##################################################################################### ## ## MOD Title: AUCTION MOD 1.3m ## MOD Author: FR (www.phpbb-auction.com) ## MOD Description: - ## MOD Version: 1.3m ## ## Installation Level: (Middle) ## Installation Time: till your done ## ## Requirements: A running phpBB 2.0.x (lastest version recommended) ## GD 1.8.x - 2.0 or higher (require for auto-thumbnail ## HTTP File Upload Enabled ## ## Tested with: __________ ## ## Files To Edit: viewonline.php ## viewtopic.php ## admin/index.php ## includes/usercp_viewprofile.php ## includes/page_header.php ## language/lang_english/lang_admin.php ## language/lang_english/lang_main.php ## templates/subSilver/subSilver.cfg ## templates/subSilver/overall_header.tpl ## templates/subSilver/viewtopic_body.tpl ## templates/subSilver/profile_view_body.tpl ## ## Included Files: to much to mention ## ##################################################################################### ## ## Before Adding This MOD To Your Forum, You Should Back Up All Files ## Related To This MOD ## ##################################################################################### ## ## For Security Purposes, you should check www.phpbb-auction.com for news and patches ## ##################################################################################### ## ## Author Notes: ## ## ##################################################################################### ## ## This hack is released under the GPL License. ## This hack can be freely used, but not distributed, without permission. ## Intellectual Property is retained by the author listed above. ## ##################################################################################### # # If you have the phpbb-auction 1.2m installed you should use the update.txt # document. # # #-----[ COPY ]------------------------------------------------------- # # Upload all files in directory "phpbb_root" with their structure to your # phpBB root directory # # Remember to upload all the language files and template files to all your # language packs and template directories # # If you use FTP please remember to use ASCII mode for text files (*.php, *.tpl) # and BINARY mode for image files (*.jpg, *.gif) # Fortunately good FTP clients today can auto-detect the mode for your files # #-----[ ACTION ]-------------------------------------- # Require for Unix-like host (you can use your FTP client to do this) # # CHMOD 777 auction/upload/ # CHMOD 777 auction/upload/cache/ # CHMOD 777 auction/upload/main/ # CHMOD 777 auction/upload/main/watermark/ # CHMOD 777 auction/upload/mini/ # CHMOD 777 auction/upload/tmp/ # CHMOD 777 auction/upload/wmk/ # CHMOD 777 auction/upload/watermark/ # CHMOD 777 auction/upload/wmk/main_watermark.png # CHMOD 777 auction/upload/wmk/big_watermark.png # #-----[ ACTION ]-------------------------------------- # # Run the install_db.php and delete (!!!) the file afterwards //////////////////////////////////////////////////////////////////////////////// 3 - Perform the following filechanges //////////////////////////////////////////////////////////////////////////////// # #-----[ OPEN ]------------------------------------------ # viewonline.php # #-----[ FIND ]------------------------------------------ # include($phpbb_root_path . 'includes/page_header.'.$phpEx); # #-----[ AFTER, ADD ]------------------------------------------ # include($phpbb_root_path . 'auction/auction_common.'.$phpEx); # #-----[ FIND ]------------------------------------------ # case PAGE_FAQ: $location = $lang['Viewing_FAQ']; $location_url = "faq.$phpEx"; break; # #-----[ AFTER, ADD ]------------------------------------------ # case AUCTION_ROOM: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_OFFER: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_RATING: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_FAQ: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_MYAUCTION: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_OFFER_VIEW: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_SITEMAP: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_PIC_MANAGER: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; # #-----[ OPEN ]------------------------------------------ # admin/index.php # #-----[ FIND ]------------------------------------------ # require('./pagestart.' . $phpEx); # #-----[ AFTER, ADD ]------------------------------------------ # include($phpbb_root_path . 'auction/auction_common.'.$phpEx); # #-----[ FIND ]------------------------------------------ # # 2 times case PAGE_FAQ: $location = $lang['Viewing_FAQ']; $location_url = "index.$phpEx?pane=right"; break; # #-----[ AFTER, ADD ]------------------------------------------ # # 2 times case AUCTION_ROOM: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_OFFER: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_RATING: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_FAQ: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_MYAUCTION: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_OFFER_VIEW: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_SITEMAP: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_PIC_MANAGER: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; # #-----[ OPEN ]------------------------------------------ # /language/lang_english/lang_admin.php # #-----[ FIND ]------------------------------------------ # $lang['Styles'] = 'Styles Admin'; # #-----[ AFTER, ADD ]------------------------------------------ # $lang['Auction'] = 'Auction'; $lang['a1_configuration'] = 'Configuration'; $lang['a2_roommangement'] = 'Manage Rooms'; $lang['a4_coupons'] = 'Manage Coupons'; $lang['a3_offer'] = 'Manage Offers'; $lang['a5_ipn_log'] = 'Manage IPN Log'; $lang['a6_picture_Configuration'] = 'Manage Images'; $lang['a7_permission'] = 'Manage Permissions'; $lang['a8_account'] = 'Manage Account'; # #-----[ OPEN ]------------------------------------------ # /templates/subSilver/subSilver.cfg # #-----[ FIND ]------------------------------------------ # $current_template_images = $current_template_path . "/images"; # #-----[ AFTER, ADD ]------------------------------------------ # $images['auction_locked']="$current_template_images/auction_locked.gif"; $images['auction_open']="$current_template_images/auction_open.gif"; $images['icon_auction_delete']="$current_template_images/auction_delete.gif"; $images['icon_auction_move']="$current_template_images/auction_move.gif"; $images['icon_auction_pic']="$current_template_images/auction_pic.gif"; $images['icon_auction_no_pic']="$current_template_images/auction_nopic.gif"; $images['icon_auction_down']="$current_template_images/auction_down.gif"; $images['icon_auction_up']="$current_template_images/auction_up.gif"; $images['icon_auction_feature']="$current_template_images/auction_feature.gif"; $images['icon_rating1']="$current_template_images/rating/1.gif"; $images['icon_rating2']="$current_template_images/rating/2.gif"; $images['icon_rating3']="$current_template_images/rating/3.gif"; $images['icon_rating4']="$current_template_images/rating/4.gif"; $images['icon_auction_watch']="$current_template_images/auction_add.gif"; $images['icon_auction_user_rating'] = "$current_template_images/{LANG}/icon_auction_user_rating.gif"; $images['newoffer'] = "$current_template_images/{LANG}/newoffer.gif"; $images['direct_sell'] = "$current_template_images/{LANG}/auction_buy_now.gif"; $images['vote_left'] = "$current_template_images/vote_lcap.gif"; $images['vote_right'] = "$current_template_images/vote_rcap.gif"; $images['auction_vote_right'] = "$current_template_images/auction_voting_barb.gif"; $images['auction_vote'] = "$current_template_images/auction_voting_bar.gif"; # #-----[ OPEN ]------------------------------------------ # /language/lang_english/lang_main.php # #-----[ FIND ]------------------------------------------ # $lang['datetime']['Dec'] = 'Dec'; # #-----[ AFTER, ADD ]------------------------------------------ # // Auction $lang['Auction'] = 'Auction'; # #-----[ OPEN ]------------------------------------------ # /templates/subSilver/overall_header.tpl # #-----[ FIND ]------------------------------------------ # <a href="{U_GROUP_CP}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_groups.gif" width="12" height="13" border="0" alt="{L_USERGROUPS}" hspace="3" />{L_USERGROUPS}</a> # #-----[ AFTER, ADD ]------------------------------------------ #   <a href="{U_AUCTION}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_auction.gif" width="12" height="13" border="0" alt="{L_AUCTION}" hspace="3" />{L_AUCTION}</a> # #-----[ OPEN ]------------------------------------------ # includes/page_header.php # #-----[ FIND ]------------------------------------------ # 'L_FAQ' => $lang['FAQ'], # #-----[ AFTER, ADD ]------------------------------------------ # 'L_AUCTION' => $lang['Auction'], # #-----[ FIND ]------------------------------------------ # 'U_FAQ' => append_sid('faq.'.$phpEx), # #-----[ AFTER, ADD ]------------------------------------------ # 'U_AUCTION' => append_sid('auction.'.$phpEx), # #-----[ OPEN ]------------------------------------------ # viewtopic.php # #-----[ FIND ]------------------------------------------ # include($phpbb_root_path . 'includes/bbcode.'.$phpEx); # #-----[ AFTER, ADD ]------------------------------------------ # // Start Include language file $language = $board_config['default_lang']; if( !file_exists($phpbb_root_path . 'language/lang_' . $language . '/lang_auction.'.$phpEx) ) { $language = 'english'; } include($phpbb_root_path . 'language/lang_' . $language . '/lang_auction.' . $phpEx); // end include language file # #-----[ FIND ]------------------------------------------ # 'L_MINI_POST_ALT' => $mini_post_alt, # #-----[ AFTER, ADD ]------------------------------------------ # 'AUCTION_USER_RATING' => "<a href=" . append_sid("auction_rating.php?mode=view&" . POST_USERS_URL . "=" .$poster_id ) . "><img src=" . $images['icon_auction_user_rating'] . " alt='Feedback Rating' border='0' /></a>", 'L_VIEW_AUCTION_USER_RATING' => $lang['auction_user_rating'], # #-----[ OPEN ]------------------------------------------ # includes/usercp_viewprofile.php # #-----[ FIND ]------------------------------------------ # if ( !defined('IN_PHPBB') ) { die("Hacking attempt"); exit; } # #-----[ AFTER, ADD ]------------------------------------------ # // Start Include language file $language = $board_config['default_lang']; if( !file_exists($phpbb_root_path . 'language/lang_' . $language . '/lang_auction.'.$phpEx) ) { $language = 'english'; } include($phpbb_root_path . 'language/lang_' . $language . '/lang_auction.' . $phpEx); // end include language file # #-----[ FIND ]------------------------------------------ # 'AVATAR_IMG' => $avatar_img, # #-----[ AFTER, ADD ]------------------------------------------ # 'AUCTION_USER_RATING' => "<a href=\"" . append_sid("auction_rating.php?mode=view&" . POST_USERS_URL . "=" . $profiledata['user_id'] ) . "\"><img src=\"" . $images['icon_auction_user_rating'] . "\" alt=\"" . $lang['auction_user_rating'] . "\" title=\"" . $lang['auction_user_rating'] . "\" border=\"0\" /></a>", 'L_VIEW_AUCTION_USER_RATING' => $lang['auction_user_rating'], # #-----[ OPEN ]------------------------------------------ # /templates/subSilver/viewtopic_body.tpl # #-----[ FIND ]------------------------------------------ # {postrow.MSN_IMG} # #-----[ AFTER,ADD ]------------------------------------------ # // Goes in same line before {postrow.MSN_IMG} {postrow.AUCTION_USER_RATING} # #-----[ OPEN ]------------------------------------------ # /templates/subSilver/profile_view_body.tpl # #-----[ FIND ]------------------------------------------ # <tr> <td valign="middle" nowrap="nowrap" align="right"><span class="gen">{L_AIM}:</span></td> <td class="row1" valign="middle"><span class="gen">{AIM_IMG}</span></td> </tr> # #-----[ AFTER, ADD ]------------------------------------------ # <tr> <td valign="middle" nowrap="nowrap" align="right"><span class="gen">{L_VIEW_AUCTION_USER_RATING}:</span></td> <td class="row1" valign="middle"><span class="gen">{AUCTION_USER_RATING}</span></td> </tr> # #-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ # ##################################################################################### ## Further Information ## ## Thats it! You are through. If you have any questions dont hesitate to use the ## Support Forums on www.phpbb-auction.com. If you want to use the payment methods ## you should read the documentation for it on the projects website. ## Greetings and have fun with phpbb-Auction ## FR ## EoM #####################################################################################
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值