Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Objective
In this tutorial we will use both rules and token modules to redirect to a specific page when a user id matches X. Where X can be any number. This tutorial is for absolute beginners. If you consider yourself an advanced user find the README.txt file that comes with the module.
Requirements
- Drupal 6.x
- Rules module 6.x-1.2 or more recent
- Token module 6.x-1.12 or more recent
- We assume that the Token sub-module
Token actions
is activated - We assume that the page you want to redirect to is already created
- We assume that you know the user id. In this tutorial we will use the user id 5
Steps
- Go to
admin/rules/trigger
- Click on
Add new rule
tab/link to create a new rule - In
Label
field type in anything. In this example we type inOn (uid=5) login redirect to 'page/section/example' page
- Under
Event
selectUser has logged in
option - Leave other options to their default settings
- Click on
Save changes
button - On the next screen click on
Add an action
link - Under
Select an action to add:
selectPage redirect
option - Click on
Next
button - On the next screen fill the
To:
field. You must type in the URL of the page you want to redirect to. Without theIn this example we type inhttp://www.domain-name.com/
page/section/example
. Leave?
and#
fields empty unless you know what you're doing ;). Check the optionForce redirecting to the given path, even if a destination parameter is given
- Click on
Save
button - On the next screen click on
Add an condition
link - Under
Select a condition to add:
selectNumeric comparison
option - Click on
Next
button - On the next screen in the
Number 1:
field type in[account:uid]
token. in theNumber 2:
field type in5
. Where5
is the user id. This number can be anything. Leave all other settings to their default. - Click on
Save
button - That's it you have successful created a rule to redirect a user on login if user id match 5.
- To test simply log-in with user id 5. You'll be redirected to the
page/section/example
Comments
Tutorial 12: On login if user id match X then redirect to a page
I tried, but after login it still directs to homepage. Anything went wrong?
same here. wont work.
same here. wont work.
Trigger module should also be enabled.
It worked like a charm with all three modules enabled.