I have a subdomain pointing at my site; I'd like people who enter the site via that subdomain to go to a different front page from those entering via the regular domain. I'm using Drupal v6.15 and module version 6.x-1.2; I tried adapting the steps in #142796: Front Page Designation based on theme but without success so far - with the settings and code below it always redirects to /node, no matter the domain. Any help gratefully received - my PHP knowledge is very minimal, so the problem's probably very obvious.

Module permissions: enabled for me

Settings:
- select type: Redirect
- Redirect to: node
- Allow embedded PHP code...: yes

<?php

$newfront = 'scottishhandbooks'; // specify where subdomain users are redirected
$regularfront = 'front'; // specify where other users are redirected
$checkdomain = <a href="http://newscot.cpag.org.uk;" title="newscot.cpag.org.uk;" rel="nofollow">newscot.cpag.org.uk;</a> // the domain name you want to redirect visitors coming from

$comingfrom = $_SERVER["HTTP_REFERRER"]; // checks to see where the visitor is coming from
if (stristr($comingfrom, $checkdomain))
      {
        // redirect users coming from $checkdomain to $newfront
        drupal_goto($path = $newfront, $query = NULL, $fragment = NULL);   
      }
  else {
         // redirect regular users to $regularfront
         drupal_goto($path = $regularfront, $query = NULL, $fragment = NULL);
        }  
?>

Comments

Dublin Drupaller’s picture

Assigned: Unassigned » Dublin Drupaller

you're redirecting to node. that will just redirect everyone to /node

I would tend to put the snippet in the front_page settings and select THEMED instead of redirect.

as an example see below where the node ID for the regular front page is 13.

$newfront = '/node/12'; // specify the node ID where subdomain users are redirected
$regularfront = '13'; // specify the node ID of the regular front page
$checkdomain = <a href="http://newscot.cpag.org.uk;" title="newscot.cpag.org.uk;" rel="nofollow">newscot.cpag.org.uk;</a> // the domain name you want to redirect visitors coming from

$comingfrom = $_SERVER["HTTP_REFERRER"]; // checks to see where the visitor is coming from
//check to see where the visitor came from
if (stristr($comingfrom, $checkdomain))
      {
        // redirect users coming from $checkdomain to $newfront
        drupal_goto($path = $newfront, $query = NULL, $fragment = NULL);  
      }
  else {
         // display the regular front page
        $node = node_load($regularfront);
        print $node->title;
        print $node->body ;
        }  

hope that helps

dub

adam_b’s picture

Not working for me, I'm afraid. I entered:

Settings:
- select type: themed
- Redirect to: [blank]
- Allow embedded PHP code...: yes

Code:

<?php
$newfront = '/scottishhandbooks'; // specify the node ID where subdomain users are redirected
$regularfront = '275'; // specify the node ID of the regular front page
$checkdomain = <a href="http://newscot.cpag.org.uk;" title="newscot.cpag.org.uk;" rel="nofollow">newscot.cpag.org.uk;</a> // the domain name you want to redirect visitors coming from

$comingfrom = $_SERVER["HTTP_REFERRER"]; // checks to see where the visitor is coming from
//check to see where the visitor came from
if (stristr($comingfrom, $checkdomain))
      {
        // redirect users coming from $checkdomain to $newfront
        drupal_goto($path = $newfront, $query = NULL, $fragment = NULL); 
      }
  else {
         // display the regular front page
        $node = node_load($regularfront);
        print $node->title;
        print $node->body ;
        } 
?>

For the normal domain (http://new.cpag.org.uk) I get Parse error: syntax error, unexpected '<' in /var/www/vhosts/cpa/includes/common.inc(1685) : eval()'d code on line 4, but if I go directly to http://new.cpag.org.uk/node/275 it works fine.

For the subdomain (http://newscot.cpag.org.uk) I get an "Access denied" error, but if I go directly to http://newscot.cpag.org.uk/scottishhandbooks (a view page, so there isn't a node ID) it works fine.

Dublin Drupaller’s picture

change line 4 to this:

$checkdomain = 'http://newscot.cpag.org.uk';
or this:
$checkdomain = 'newscot.cpag.org.uk';

and make sure you have permissions correctly setup for the front_page under users-> access control.

if the redirect to the view page is still giving you grief....change it from a goto to an embed view instead.

hope that helps

dub

adam_b’s picture

Okay... the "Access denied" problem was a permissions issue, as you suggested.

Now I'm getting the default front page (node/275) for both domains - and the page text isn't being rendered properly. The source code is missing the [h1] and [p] tags, as in:

<div id="content-area">
Welcome to the CPAG live websiteThis website is for Child Poverty Action Group work. It will become the live site but in the meantime, expect content to appear, disappear, or change without notice.

Note that this site is normally only visible from within CPAG offices - if you need to access it from outside these locations, please contact Adam.</div>

I've tried both alternatives for line 4; I'm not certain what you meant by "embed" but I tried changing drupal_goto to drupal_embed - didn't appear to make any difference.

Any more ideas?

mrgoltra’s picture

subscribing

simon georges’s picture

Is there still an issue with latest versions?

simon georges’s picture

Status: Active » Closed (won't fix)

The 6.x version of "Front page" is not maintained any more. This issue is closed for this reason.
Please upgrade to a supported version of the module and re-open if you still have the issue.