Jump to content

Redirect issues conflicting with mobile site


icreation
 Share

Recommended Posts

For best practice best-of-scotland.co.uk redirects to www.best-of-scotland.co.uk and this was done by adding these lines to the core htaccess file:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
 
However, we also have a mobile site working on a parked domain using this method:
 
index.php has the following lines changed to make sure the site directory is hard coded instead on a variable
 
$config->urls->siteModules = "site/modules/";
$assetsDir = "site/assets";
$config->urls->adminTemplates = is_dir("site/$adminTplDir") ? "site/$adminTplDir/" : "$wireDir/$adminTplDir/";
 
I copied index.config.php from wire to the root and added these line:
 
function ProcessWireHostSiteConfig() {
return array(
'mobile.best-of-scotland.co.uk' => 'site-mobile',
'best-of-scotland.co.uk' => 'site',
'www.best-of-scotland.co.uk' => 'site',
                );
}
 
The problem is that I can't get the two to work together. If I remove the www redirect from the htaccess file the mobile site works. Adding it in stops it working.
 
Can anyone help here please? Or is there a better method for delivering mobile sites?
 
Thanks
 
Mike
Link to comment
Share on other sites

That Apache redirect rule is essentially saying "if the hostname doesn't start with 'www' then redirect to www.hostname.com". That rule would not be compatible with a site that you are using to serve content to different hostnames. If 'mobile' is the only other hostname you need to serve, you might try adding it as an OR condition, i.e. "if hostname doesn't start with 'www' OR 'mobile' then redirect to www.hostname.com":

RewriteCond %{HTTP_HOST} !^(www|mobile)\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
  • Like 4
Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...