Code: Select all
Redirect
Code: Select all
$start = request_var('start', 0);
Code: Select all
// We must fetch current forum_id to check differences and to inject correct
//$forum_id if missing. Also added cache after comments from Amigojack
$sql = 'SELECT forum_id
FROM ' . TOPICS_TABLE . "
WHERE topic_id = $topic_id";
$result = $db->sql_query($sql, 86400);
$correct_f = (int) $db->sql_fetchfield('forum_id');
// #1 Redirect, if parameter "f" missing, add it and 301 permanent
if ($topic_id && !$forum_id){
$viewtopic_build_url = 'f=' . $correct_f . '&t=' . $topic_id;
if ($topic_id && $start){
$viewtopic_build_url = 'f=' . $correct_f . '&t=' . $topic_id . '&start=' . $start;
}
$vt_new_furl = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $viewtopic_build_url);
$vt_new_furl = str_replace('&', '&', $vt_new_furl);
header("HTTP/1.1 301 Moved Permanently");
header("Location:" . $vt_new_furl);
header("Connection: close");
}
// End of #1, start of second redirect, if topic where moved, assign correct forum_id and 301 permanent
if ($forum_id !== $correct_f) {
$correct_string_url = 'f=' . $correct_f . '&t=' . $topic_id;
if ($topic_id && $start){
$correct_string_url = 'f=' . $correct_f . '&t=' . $topic_id . '&start=' . $start;
}
$new_301 = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $correct_string_url);
$new_301 = str_replace('&', '&', $new_301);
header("HTTP/1.1 301 Moved Permanently");
header("Location:" . $new_301);
header("Connection: close");
}
//Redirect #2 end
function redirect()
),AmigoJack wrote:Congratulations: you
- increased the database load without thinking of a cache or how to optimizing it a bit,
- will loop redirects on global topics,
- won't have a redirect fallback for servers not supporting it (see
function redirect()
),- won't act on posts (just on topics) as input,
- created redundant code: why not executing the very same SELECT at the beginning?
Would you like to help or only be cheeky?olsserik wrote:If someone with knowledge sees anything wrong with it, please post an update or comment.
With global topics (User guide 5.4.4.1: Topic Types > Global), those forum IDs areolsserik wrote:But I can not make it loop with a global topic, when would this apply?
0
, hence your code if ($topic_id && !$forum_id){
will evaluate to TRUE for each request.Thanks.AmigoJack wrote:With global topics (User guide 5.4.4.1: Topic Types > Global), those forum IDs areolsserik wrote:But I can not make it loop with a global topic, when would this apply?0
, hence your codeif ($topic_id && !$forum_id){
will evaluate to TRUE for each request.
Code: Select all
if ($forum_id !== 0)
First of all: it "works", since you're getting a page. Please stop being this imprecise. Second: it's phpbb.com's stupid JavaScript that modifies the outcome of that URI - disable JavaScript and the site loads as it should. I created WEBSITE-1245 for this bug.olsserik wrote:The link above does not work for me.
Then half of your code would never be executed. You wanted to add missing forum IDs - did you forget that already?olsserik wrote:I guess the simplest is to wrap the whole code in an
So you never foundolsserik wrote:any predefined check
if (!$forum_id)
in the original code of that file, hence never considered moving your code? Plus the constant POST_GLOBAL
seems also new to you?