Getting the correct path to our secure subdomain

edited August 2014 in Share
We have a site that will be going live soon that has an area for members and signup that is secure, and hosted elsewhere. It will live at https://secure.prontocycleshare.com whereas the rest of the site will live at http://www.prontocycleshare.com/

Is there a way to use the My Url helper to be able to use the internal linking syntax <?=site_url('internal-link')?> for this subdomain? I feel like that is a better practice than hard coding in case we ever move domains etc.

PS Thanks for putting up with my recent uptick in questions as we launch a new site using the new 1.1 for the first time. It is much appreciated.

Comments

  • edited 2:53AM
    The site_url function derives it's domain from the BASE_URL constant that is set in the main CI config. This value will dynamically change based on the domain that the site is being served from. However, if need be you can change this value (e.g. $this->config->set_item('base_url', 'www.prontocycleshare.com') )
    $config['base_url'] = BASE_URL;
    Also, more as an FYI, the BASE_URL is set in the fuel_constants.php file. Does that help?
  • edited 2:53AM
    Not quite sure.

    What I'm trying to figure out is if there is a way to add a parameter to the internal link or something like that so that From either the secure or non-secure site you can reach internal pages in either site. So that it doesn't matter which site I'm on something like this:

    <?=site_url('en/map', secure)?>

    would take me to

    https://secure.prontocycleshare.com/en/map

    Just the same as

    <?=site_url('jobs')?>

    or perhaps

    <?=site_url('jobs', nonsecure)?>

    would take me to

    http://www.prontocycleshare.com/jobs
  • edited 2:53AM
    There isn't anything setup with the site_url function to automatically change the base_url like that. However, you could create your own function that does this maybe something like this:
    function url($uri, $base_url = NULL, $https = NULL, $language = NULL) { $CI =& get_instance(); $CI->config->set_item('base_url', $base_url); return site_url($uri, $https, $language); }
  • edited August 2014
    Great! I've got this working in the back end just great. But when I try to use the function in a Fuelified page e.g.

    <a href="{url('resources')}">bike shops</a>

    I get this error:


    An Error Was Encountered
    Call to a disallowed php function : url

    Is there a way I can allow this function?
  • edited 2:53AM
    You'll need to add that function in the fuel/application/config/parser.php file under the $config['parser_allowed_php_functions']
  • edited 2:53AM
    Awesome. One last question, hopefully. And this is actually part of a bigger question/conversation but relevant here.

    We set up a constant for the secure url so that we could use SECURE_BASE_URL and BASE_URL as the second parameter if/when necessary when creating these links (e.g. <?=url('map', SECURE_BASE_URL)?>

    but I forgot that constants don't parse into the Fuel admin (this has come up before when we've created urls with the system name etc)

    Is there any way to remedy this? Is this a feature others have asked for? Seems like folks would have...
  • edited 2:53AM
    Do you mean you can't do this {url('map', SECURE_BASE_URL)} in a layout field in the CMS? If so, you try adding the in the global.php file as variables that get passed to all pages created in FUEL:
    $vars['secure_base_url'] = SECURE_BASE_URL;
    Then in the CMS you can try this:
    {url('map', $secure_base_url)}
  • edited 2:53AM
    Good to know. I think we've finally gotten where we need to be. Thanks!
  • edited February 2016
    So I am reviving this thread because we have been using this semi-successfully with a minor bug that is turning into a bigger problem so I was hoping we might be able to run through it together.

    We eventually ended up with this function:

    function url($uri = '', $base_url = BASE_URL) { $CI =& get_instance(); $CI->config->set_item('base_url', $base_url); return site_url($uri); }
    But for certain elements elsewhere on the page, the base_url is not reset. What I mean by that is if I use a new base_url on the main logo of the page it persists in elements such as fuel_nav items or form_open.

    A fix we made in the meantime was to add a line to the fuel_helper file in teh fuel_nav function itself $CI->config->set_item('base_url', BASE_URL); but this seems less than ideal going into and changing a core file.

    Do you have any recommendations about how we could add a resetting of some sort to our function itself?
  • edited 2:53AM
    This is an older version of FUEL correct?
  • edited 2:53AM
    Actually we are experiencing the same problem even in an upgrade, which is why this is coming up now. We figured it would not be a problem in 1.3 but it was in an older 1.1 version and now we are working on a 1.3 upgrade and still finding it.
  • edited 2:53AM
    The site_url function has been modified in newer versions of FUEL to include a second parameter that can determine https (TRUE), or http (FALSE) or NULL with NULL defaulting to whatever the BASE_URL constant is.
  • edited 2:53AM
    That's awesome. Unfortunately, it's not just http vs https but that we have a whole different subdomain for the "secure" (really it's "member") site, so I'm not sure we can just use site_url. It would be switching between something like www.cogobikeshare.com and member.cogobikeshare.com that is actually on a totally separate instance of Fuel.

    Initially we made that separation because a partner was handling the member site, now we are also doing so on our own sites to get the non-member, marketing site completely out of PCI scope.
  • edited 2:53AM
    Nevermind, we got it!

    For reference:

    function url($uri = '', $base_url = FALSE) { if ($base_url == FALSE ) { return site_url($uri); } $CI =& get_instance(); $CI->config->set_item('base_url', $base_url); $url = site_url($uri); $CI->config->set_item('base_url', BASE_URL); return $url; }
Sign In or Register to comment.