Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

Use Drupal global variable $base_root for that.

share|improve this answer
    
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"; ?> –  Patrick Kenny Aug 29 '13 at 16:32
add comment

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

<?php
global $user;
$user->language;
?>

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

share|improve this answer
    
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. –  Patrick Kenny Aug 2 '12 at 17:21
add comment

Try this:

<?php substr(url('<front>', array('absolute' => TRUE)), 0, -2); ?>
share|improve this answer
    
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). –  Patrick Kenny Jan 8 '13 at 14:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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