[resolved] iPhones aren't redirecting to mobile site

brenpsnow
12 years, 9 months ago
I have Domain Support set to "yes." I have redirect to domain under iphone/ipod set to "yes." My mobile site works great, but iPhones aren't being redirected. I've cleared cookies and used other phones. I've tried to force a redirect using htaccess, but my mobile site shares the same htaccess so I get a redirect loop. My rewrite conditions follow, any advice would be great.

RewriteCond %{HTTP_HOST} ^flagshiptutors.com$ [NC]
RewriteRule ^(.*)$ www.flagshiptutors.com/$1 [R=301,L]
smeako
12 years, 9 months ago
Hi Guys, am struggling with this one. Can't seem to get my site to re-direct for iphone. Domain is diggerscc.com/myjoomla and subdomain is iphone.diggerscc.com.

Here is my domains.php file code for reference. Couldn't get it to laod as attachment for some reason.

<?php
/**
* ###DESC###
* ###URL###
*
* @version ###VERSION###
* @license ###LICENSE###
* @copyright ###COPYRIGHT###
* @date ###DATE###
*/
defined('_JEXEC') or die('Restricted access');

jimport('joomla.plugin.plugin');

class plgMobileDomains extends JPlugin
{
var $_domain_markup = null;

function plgMobileDomains(& $subject, $config)
{
parent::__construct($subject, $config);
}

function onAfterDeviceDetection(&$MobileJoomla_Settings, &$MobileJoomla_Device)
{
$is_joomla15 = (substr(JVERSION,0,3) == '1.5');
if($is_joomla15)
$config_live_site = 'config.live_site';
else
$config_live_site = 'live_site';

$this->getSchemePath($http, $base);

$markup = $MobileJoomla_Device['markup'];
$host = $_SERVER['HTTP_HOST'];
$domain_xhtml = $MobileJoomla_Settings['xhtml.domain'];
$domain_wml = $MobileJoomla_Settings['wml.domain'];
$domain_chtml = $MobileJoomla_Settings['chtml.domain'];
$domain_iphone = $MobileJoomla_Settings['iphone.domain'];

/** @var JRegistry $config */
$config =& JFactory::getConfig();

// Check for current domain
if(($markup=='xhtml' && $domain_xhtml && $host==$domain_xhtml) ||
($markup=='wml' && $domain_wml && $host==$domain_wml) ||
($markup=='chtml' && $domain_chtml && $host==$domain_chtml) ||
($markup=='iphone' && $domain_iphone && $host==$domain_iphone) )
{
$config->setValue($config_live_site, $http.'://'.$host.$base);
$this->_domain_markup = $markup;
return;
}

if($domain_xhtml && $host == $domain_xhtml)
{ // Smartphone (xhtml-mp/wap2) domain
$MobileJoomla_Device['markup'] = 'xhtml';
$config->setValue($config_live_site, $http.'://'.$host.$base);
$this->_domain_markup = $markup;
}
elseif($domain_iphone && $host == $domain_iphone)
{ // iPhone/iPod domain
$MobileJoomla_Device['markup'] = 'iphone';
$config->setValue($config_live_site, $http.'://'.$host.$base);
$this->_domain_markup = $markup;
}
elseif($domain_chtml && $host == $domain_chtml)
{ // iMode (chtml) domain
$MobileJoomla_Device['markup'] = 'chtml';
$config->setValue($config_live_site, $http.'://'.$host.$base);
$this->_domain_markup = $markup;
}
elseif($domain_wml && $host == $domain_wml)
{ // WAP (wml) domain
$MobileJoomla_Device['markup'] = 'wml';
$config->setValue($config_live_site, $http.'://'.$host.$base);
$this->_domain_markup = $markup;
}
else
{ // Desktop domain
$app =& JFactory::getApplication();
// is it non-first visit? Then don't redirect
if($app->getUserState('mobilejoomla.markup') !== null)
$MobileJoomla_Device['markup'] = '';
}
}

function onBeforeMobileMarkupInit(&$MobileJoomla_Settings, &$MobileJoomla_Device)
{
$markup = $MobileJoomla_Device['markup'];
$host = $_SERVER['HTTP_HOST'];
$domain_xhtml = $MobileJoomla_Settings['xhtml.domain'];
$domain_wml = $MobileJoomla_Settings['wml.domain'];
$domain_chtml = $MobileJoomla_Settings['chtml.domain'];
$domain_iphone = $MobileJoomla_Settings['iphone.domain'];

if($this->_domain_markup !== null)
{
if(!(($markup=='xhtml' && $domain_xhtml && $host==$domain_xhtml) ||
($markup=='wml' && $domain_wml && $host==$domain_wml) ||
($markup=='chtml' && $domain_chtml && $host==$domain_chtml) ||
($markup=='iphone' && $domain_iphone && $host==$domain_iphone)))
$MobileJoomla_Device['markup'] = $this->_domain_markup;
}

if($markup == '')
return;

$http = 'http';
if(isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off'))
$http .= 's';

$uri =& JURI::getInstance();
$parsed = parse_url($uri->toString());
$path = isset($parsed['path']) ? $parsed['path'] : '/';

/** @var JSite $app */
$app =& JFactory::getApplication();
switch($markup)
{
case 'xhtml':
if($domain_xhtml && $host != $domain_xhtml)
$app->redirect($http.'://'.$domain_xhtml.$path);
break;
case 'wml':
if($domain_wml && $host != $domain_wml)
$app->redirect($http.'://'.$domain_wml.$path);
break;
case 'chtml':
if($domain_chtml && $host != $domain_chtml)
$app->redirect($http.'://'.$domain_chtml.$path);
break;
case 'iphone':
if($domain_iphone && $host != $domain_iphone)
$app->redirect($http.'://'.$domain_iphone.$path);
break;
}
}

function getSchemePath(&$http, &$base)
{
if(isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off'))
$http = 'https';
else
$http = 'http';

$app =& JFactory::getApplication();
$live_url = $app->getCfg('live_site');
if($live_url)
{
$parsed = parse_url($live_url);
if($parsed !== false)
{
$base = isset($parsed['path']) ? $parsed['path'] : '/';
return;
}
}

if(strpos(php_sapi_name(), 'cgi') !== false && !empty($_SERVER['REQUEST_URI']) &&
(!ini_get('cgi.fix_pathinfo') || version_compare(PHP_VERSION, '5.2.4', '<')))
$base = rtrim(dirname(str_replace(array('"','<','>',"'"), '', $_SERVER['PHP_SELF'])), '/\\');
else
$base = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
}
}
dryabov
12 years, 9 months ago
Just set iphone.diggerscc.com as a subdomain name in Advanced tab of MJ settings. And note that MJ keeps path of URL, so full URL of mobile version will be iphone.diggerscc.com/myjoomla
smeako
12 years, 9 months ago
Hi Dryabov,

Thank you for your response. I have now set the subdomain in MJ Advanced to iphone.diggerscc.com
Now when I type the full url diggerscc.com/myjoomla into the iphone it does re-direct to iphone.diggerscc,com/myjoomla but shows a hostgator error 404 and can't find the page.
If i manually type iphone.diggerscc.com into the iphone however the correct page shows. Do i have something configured incorrectly with my hosting account. I have set up the subdomain iphone.diggerscc.com in hostgator and added /myjoomla after public_html

Thanks
dryabov
12 years, 9 months ago
 I have set up the subdomain iphone.diggerscc.com in hostgator and added /myjoomla after public_html

I don't know what options hostgator has for subdomains, but usually it's sufficient to set "Document Root" path of subdomain to be the same as main domain has.
smeako
12 years, 9 months ago
I'm not sure what exactly is meant by "Document Root". Am I correct in thinking the document root folder for my site at diggerscc.com/myjoomla would be public_html/myjoomla or would it simply be public_html? therefore if I remove the myjoomla addition from after public_html that should then point to the document root. Sorry for my ignorance
smeako
12 years, 9 months ago
Hi Dryabov,

thanks for your help. Just fixed issue by removing /myjoomla from after public_html in the sbdomain

By continuing to use this site you consent to the use of cookies on your device as described in our cookie policy unless you have disabled them. This site will not function correctly without cookies.

I accept cookies from this site.