How do I redirect users to the page they were before logging in to my site? I´ve got a Drupal site that after the user logs in it is redirected to his profile.
I want to create a specific rule so people from specific characteristics can retur to the page they were before they´ve logged in.

I´m planning to do that with the rules module.

So, I´ve set the parameters and conditions, but when I try to create the rule, telling Drupal where it should redirect people, I just don´t know how to say that.

I think I should put some php code inside that page redirect rule, but don´t know how.
Hopw you can help me out.

FYI, I've tried (unsuccessfully) this:

$_SESSION['redirect_to'] = $_SERVER['REQUEST_URI'];
header("Location: http://www.mysite.net/user");
exit();

// On successful login
$redirect = $_SESSION['redirect_to'];
// unset the session var
unset($_SESSION['redirect_to']);
header("Location: http://www.mysite.net/$redirect");
exit();
Have a look at the Login Destination module.

In custom code, to issue a redirect in Drupal use the drupal_goto() function. Drupal has a massive API, use it.