Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

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

mobile module: redirecting to a specific page

Go to End



126 Posts

1 July 2011 at 2:10pm

Edited: 01/07/2011 2:18pm


I made a small change to the mobile module because I prefer that links to a specific page should be redirected to the same page under the mobile subdomain, so something like should redirect to (not to the default

Mainly because if I get a link by email or through another page I would end up on the home page, not on the actual page the link should go to.

It's an easy fix. In MobileSiteControllerExtension, method onBeforeInit add $this->owner->RelativeLink() to both redirect functions.

return $this->owner->redirect($config->FullSiteDomain . $this->owner->RelativeLink());

Or, if you also have modules installed that use the 'Action' and 'ID' URL parameters (such as the Image Gallery, e.g. ) you could add the code in green:

	 * Override the default behavior to ensure that if this is a mobile device
	 * or if they are on the configured mobile domain then they receive the mobile site.
	public function onBeforeInit() {
		$config = SiteConfig::current_site_config();
		$URLParams = Director::URLParams();
		if ($this->owner->RelativeLink() != '/') $url_params = $this->owner->RelativeLink();
		if ($URLParams['Action']) $url_params .= $URLParams['Action'].'/';
		if ($URLParams['ID']) $url_params .= $URLParams['ID'];
		if ($URLParams['OtherID']) $url_params .= '/'.$URLParams['OtherID'];

		// Redirect users to the full site if requested (cookie expires in 30 minutes)
		if(isset($_GET['fullSite'])) {
			$_COOKIE['fullSite'] = 1;
			setcookie('fullSite', 1, time() + self::$cookie_expire_time);

		// Redirect to the full site if user requested
		if($this->onMobileDomain() && !empty($_COOKIE['fullSite']) && $config->MobileSiteType == 'RedirectToDomain') {
			return $this->owner->redirect($config->FullSiteDomain . $url_params);
		} elseif(!empty($_COOKIE['fullSite'])) {
			return; // nothing more to be done

		// If the user requested the mobile domain, set the right theme
		if($this->onMobileDomain()) {

		// User just wants to see a theme, but no redirect occurs
		if(MobileBrowserDetector::is_mobile() && $config->MobileSiteType == 'MobileThemeOnly') {

		// If on a mobile device, but not on the mobile domain and has been setup for redirection
		if(!$this->onMobileDomain() && MobileBrowserDetector::is_mobile() && $config->MobileSiteType == 'RedirectToDomain') {
			return $this->owner->redirect($config->MobileDomain . $url_params);

There may be a more 'pretty' solution, but for me this works.