I have created a rule set to handle login redirects for users on my site. If a user logs in from a page that is set to a different language from that user's language (example: English user logs in on a Japanese page), the user will be redirected to a page with the same language as the page upon which they logged in (in the example, a Japanese page).

To fix this, I want to force my redirects to be the appropriate language path based on the user language.

However, the [site:url] replacement pattern which is provided by Rules includes the language path (because it is the front page).

My front page is https://mysite.com/en.

I want to create a new variable which is the URL of my site minus the language path: https://mysite.com/

I tried creating a variable of type text with a value of

<?php substr("[site:url]", 0, -2); ?>

but for some reason this just gives me the value of [site:url]; it appears that the substr() function has no effect. I don't understand PHP very well so I could be missing something obvious-- I just want to remove the last two characters of the [site:url]. How can I do this within Rules?


3 Answers 3


Use Drupal global variable $base_root for that.

  • Thanks! Here's an example of what I added to the redirect to go to the messages page: <? global $base_root; echo $base_root . "/messages"; ?> Commented Aug 29, 2013 at 16:32

Independent from Drupal 6 and 7, <?php url('<front>'); ?> should give the path to the front page unless you specify a language. See url()

global $user;

You can get the logged in user's prefered language from above snippet.

  • WHen I get the front page url, it includes /en (if English). I want to remove this "/en" from the front page URL, which is provided by default. In other words, I want the front page URL but without the language path appended. Commented Aug 2, 2012 at 17:21

Try this:

<?php substr(url('<front>', array('absolute' => TRUE)), 0, -2); ?>
  • Unfortunately, I tried setting this as a variable (URI and also text) but it didn't work in either case (it still returned the full string). Commented Jan 8, 2013 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.