MyBB Community Forums

Full Version: redirect invalid forum and invalid thread to home page or index?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
How do I redirect invalid forum and invalid thread to my home page or index page?
Hi really need this one anyone?

How to make this work?

/ Add hooks here
$plugins->add_hook("showthread_end", "invalidthread");

// Plugin info
function invalidthread_info()
{
	return array(
		"name"			=> "invalidthread",
		"description"	=> "invalidthread",
		"website"		=> "invalidthread",
		"author"		=> "invalidthread",
		"authorsite"	=> "invalidthread",
		"version"		=> "1.0",
		"guid" 			=> "",
		"compatibility" => "16*"
	);
}


function invalidthread() {

	global $mybb, $thread, $lang;


	if ($l['error_invalidthread']) {
		error("working");
	}
}
This sounds handy. Wouldn't it better be done through .htaccess though?
(05-10-2014, 06:02 AM)DrXotick Wrote: [ -> ]This sounds handy. Wouldn't it better be done through .htaccess though?

Hi thanks very much for your reply I though about it but don't know how to do it?

My SEO Plugin handles all errors except these I mean 404.....

How can I redirect invalid thread/forum using .htaccess?
Maybe look through this old "bug" report :

http://dev.mybb.com/issues/1622
Try this in your .htaccess. I would put it above any Google SEO code, but below rewrite engine on.

ErrorDocument 404 /index.php

If that doesn't work out, or optionally... Make your custom 404.html as:
<html>
<head>
<meta http-equiv="refresh" content="3; url=http://example.com/">
<title>Page doesn't exist. Redirecting you to homepage...</title>
</head>
<body>
Page doesn't exist. Redirecting you to homepage...
<br>
</body>
</html>
Content is the # of seconds before it will redirect. Set to 0 to make it immediate.

(obviously change example.com to your domain name.)
@DrXotick thanks very much man.

@Leefish great idea thanks a lot. I will replace all :

error($lang->error_invalidthread);
error($lang->error_invalidforum);
error($lang->error_invalidpost);

With:

if (in_array($mybb->user['usergroup'], array('3','4','6'))) {
error($lang->error_invalidthread);
}
else
{
redirect("index.php", some error goes here);
}

Just nailed it thanks Smile




P.S. Do you think I can create a plugin for this without modifying core files?
Just curious. Why would you create a plugin when you can put a single line in .htaccess

Ah. nevermind. I see you only want to target certain usergroups. Cheers.
(05-11-2014, 04:23 PM)DrXotick Wrote: [ -> ]Just curious. Why would you create a plugin when you can put a single line in .htaccess

Ah. nevermind. I see you only want to target certain usergroups. Cheers.

Hi I only want to redirect invalid forum, thread, post this is not 404!
Didn't your mom ever teach you not to yell at strangers?
Pages: 1 2