21309 Posts in 5738 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1034 Views |
-
Redirect to Subdomain for SSL

21 October 2010 at 2:40pm
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.
-
Re: Redirect to Subdomain for SSL

22 October 2010 at 12:31pm
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 classfunction 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.
| 1034 Views | ||
|
Page:
1
|
Go to Top |

