Jump to:

23489 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Redirect to Subdomain for SSL

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1259 Views
  • eceers
    Avatar
    Community Member
    24 Posts

    Redirect to Subdomain for SSL Link to this post

    My client has set up a ssl domain at https://secure.domain.com and the general site is on the normal address of http://www.domain.com.

    My question is how do I change the baseURL rather than just the protocol?

    I'm hoping this is going to be a quick one. I've been looking around for a bit and haven't been able to find much, at least not what I was searching for

    Any help would be greatly appreciated.

  • eceers
    Avatar
    Community Member
    24 Posts

    Re: Redirect to Subdomain for SSL Link to this post

    I have worked it out in a round about way.

    I created an extra function along the lines as one shown here http://doc.silverstripe.org/ssl?s[]=secure&s[]=pages

       public function init() {

          parent::init();
          
          if (!Director::isDev()) {
        if ( !$this->SecurePage()) {
        $this->force_HTTP();
        } else {
           $this->force_HTTPS();
        }
          }
    }

    // if we are on https, redirect to the http version of this page's URL
    function force_HTTP() {
    $page_url = Director::absoluteURL( $_SERVER['REQUEST_URI'] );
    $https_regex = '{^https:}';
    if ( preg_match( $https_regex, $page_url ) ) {
    $new_url = preg_replace( $https_regex, 'http:', $page_url );
    Director::redirect('http://www.domain.com'.$this->Link());
    }
    }
    function force_HTTPS() {
    $page_url = Director::absoluteURL( $_SERVER['REQUEST_URI'] );
    $https_regex = '{^http:}';
    if ( preg_match( $https_regex, $page_url ) ) {
    $new_url = preg_replace( $https_regex, 'https:', $page_url );
    Director::redirect('https://secure.domain.com'.$this->Link());
    }
    }


    Declaring in the class

    function SecurePage() {
    return false;
    }

    It may not be 100% right but it appears to work the way I need it to.

    If anyone has any suggestions to improve would be greatly appreciated.

    1259 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.