Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Redirect for alternate/mobile site version

edited December 2008 in Vanilla 1.0 Help
I'm working on a mobile add-on that uses a mirror domain to show an alternative version of a vanilla site. On page load all links are converted to the mobile version if you are viewing from the mobile domain. It works great except that when you post a discussion or comment it redirects back to the non-mobile version after saving the comment. The site urls look something like: It seems to be going bad in the Redirect function in Framework.Functions.php, but I can't tell at what point the url is getting converted back to non-mobile. Anyone have any suggestions on what a possible workaround might be? Thanks.


  • Options
    Some more info on this: On line 168 of /library/Vanilla/Vanilla.Control.DiscussionForm.php the Redirect function is called after a comment is saved. Redirect($Url); If I echo out $url it gives me my mobile site version which seems correct. In the Redirect function (line 714 - /library/Framework/Framework.Functions.php) function Redirect($Location, $Code = '303', $Name = '', $Die = 1) if I echo $Location it gives me my non-mobile site How is the function passing the right url but as soon as it gets to the Redirect function it gets changed?
  • Options
    I think instead of rewriting the URLs to the mobile version on Page load, you should manually adjust your configuration's BASE_URL parameter.

    This might be more advanced than you'd like, but in essence what you want to do is make your configuration file a little more dynamic. Depending on the how the configuration file is requested, you could set the BASE_URL accordingly.

    Basically, in your conf/settings.php file:if (strpos($_SERVER['HTTP_HOST'], 'mobile') !== false) $Configuration['BASE_URL'] = ''; else $Configuration['BASE_URL'] = '';

    The variable you use to detect the mobile version may differ, but that's probably the best and easiest way to do it. All URLs in Vanilla are based on the BASE_URL config variable, hence the "BASE" part ;)
  • Options
    Thanks for the response sirlancelot. With your tip I got it working.

    I was setting BASE_URL to the mobile url inside of my mobile class, which wasn't working. I moved it outside the class and it now works.

    if (substr_count('http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'],$Context->Configuration['MOBILE_URL'])) { $Context->Configuration['BASE_URL'] = $Context->Configuration['MOBILE_URL']; $MobileAlternative = $Context->ObjectFactory->NewContextObject($Context, "MobileAlternative"); $Page->AddRenderControl($MobileAlternative, $Configuration['CONTROL_POSITION_PAGE_END'] + 1); }

    Another question, is it better to set $Context->Configuration['MOBILE_URL'] inside my extension, or should it be added to the conf/settings.php file? I'm not clear on if there is a standard protocol.
This discussion has been closed.