MyBB Community Forums

Full Version: .htaccess 301 redirect invalid forum, thread, post?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Is there a way to 301 redirect invalid forum, thread, post with .htaccess.

I am using php 301 redirect:

header("HTTP/1.1 301 Moved Permanently");
header("refresh:3; {$mybb->settings['bburl']}");
echo 'Invalid Thread you will be redirected to homepage after 3 seconds.';

But it causing problems with IE and Google shows errors!
I really think you should use the Location instead of refresh. There are up to 3 parameter's of the header function so you could actually send a 301 status code with it.

header("Location: {$mybb->settings['bburl']}", true, 301);

Additionally, you shouldn't be having any other code execute when you use a redirect.
Could you help please. I have replaced all calls to error inside forumdisplay.php and showthread.php with:

header("Location: {$mybb->settings['bburl']}", true, 301);

so instead of calling error for invalid forum, thread, post it called header BUT the problem is Google is showing lots of errors: Not followed 301

How can I make this right?
It might take time for it to update its site map? Otherwise I'm not sure why it wouldn't follow the 301.
Do you know how can I check if the forum exists before all functions start checking their things. The problem is header is not run in the first place that is why it's not working.

If I hook to global_start will this be checked before everything:

$fid = intval($mybb->input['fid']);
   $foruminfo = get_forum($fid);
Well there is a cache for the forums. That would include its primary key (fid) so you'd be able to check that against the query string.

I think you'd be able to do something like this to get the forum cache into an array. You might want to use var_dump on the variable to see what the syntax of it will look like.

$forums = $cache->read("forums");

I think the structure would be $forums[$fid] = $fid, but I'm not 100% sure.
Is this what I have to use?

$forums = $cache->read("forums");
$forums[$fid] = $fid
Something like that. You'd have to see what $forums would actually have for keys and values. Using the var_dump function on that variable will assist you with that.
Do I have to hook to forumdisplay_start or to global_end ???????

I will also have to add $cache to:

global $mybb, $cache;
Either should work and yes you will have to add $cache as a global in your function.
Pages: 1 2 3