In older versions of vBulletin, you could specify a URL to redirect a forum to another location. This could be on your site or elsewhere. With the release of vBulletin 5, this functionality was removed. You can recreate this functionality using Template Hooks. I will outline the steps to create a channel redirect here.
This tutorial involves changing options, creating custom templates and building a temple hook.
Allowing Redirects
To get started, if the destination link of your redirect is external to your site then you must allow vBulletin to redirect to the destination. This is done in the Options within the AdminCP.
- In the AdminCP go to Settings -> Options -> Site Name / URLs / Contact Details.
- Add the full URL of your destination to the Redirect Whitelist. For example: 'https://forum.vbulletin.com'
- Save this Options page.
Creating a Channel
We need a placeholder for our redirect. To recreate the functionality from vBulletin 4, we are going to create that placeholder as a forum channel.
- In the AdminCP, go to Channel Management -> Add New Channel.
- Give it a name. For example:
vB.Com Forums
- None of the other options really matter but you can give the channel a description if you wish.
- Save the channel.
On the resulting channel list, note the Node ID for the new channel. In my example it is 106.
Create a new template
In order for this to work, we need to add a new custom template to your system. This is easy to accomplish in vBulletin.
- In the AdminCP, go to Styles -> Style Manager.
- In the row for your designated style choose "Add New Template" from the Choose Action drop down menu.
- For the new template, give it a name. Example:
forum_redirect
- Add the following code for the template:
<vb:if condition="$nodeid==106">
{vb:redirect 'https://forum.vbulletin.com'}
</vb:if>
Note: Make sure to change the nodeid (ex 106) to match the channel you created above.
- Save the template at the bottom of the editor.
Code Explanation
In order for this to work, the template uses two vBulletin Markup tags. <vb:if> and {vb:redirect}.
The <vb:if> tag allows us to check if a variable has the proper value. you only want to redirect if the nodeid of the channel matches the one you specifically created. In my case the value is 106. This comparison allows for standard PHP Comparison Operators to be used.
{vb:redirect} is a template method. This allows us to call a specific function within vBulletin's rendering engine to force a specific outcome. This method takes a URL as its parameter. If you're redirecting to a location within the vBulletin installation, this can be a partial URL. For instance to redirect to the Articles page you can use /articles
as the parameter.
Implement the Template Hook
- In the AdminCP go to Hooks & Products -> Manage Template Hooks.
- Click the "Add New Hook" link at the bottom of the list.
- Select a Hook location. Example:
header_after_body_begin
- Give the hook a title. Example:
vB.com Redirect
- We have to pass a variable to our new template for it to work. In the hook arguments field, add:
nodeid=page.nodeid
A word on Hook Arguments
Variables are not available to templates unless they are registered before the template is rendered. Normally, this is done in the PHP code. This is a security precaution so variables can be cleaned and processed before being shown to the end user. Since we have no PHP code for our new template, Hook Arguments allow us to pass one or more variables and register them. This allows us to use them in the template.
There is no definitive list of all the variables available in vBulletin. Let alone a list of which variables are available to each template. If you need to know what variables are available, look at the parent template. To find the parent template, search the hook name in the AdminCP under Styles -> Search in Templates.
Testing it Out
After saving your template hook, the redirect should be functional. Visit the front-end of your site and click on the channel that you created. It should redirect to the specified destination.