Setting conditions based on inbound URL
Permalink
Hi everyone, I have a client that was previously managing two hard-coded HTML sites, but I've moved one over to C5 so far. The sites are nearly identical, but the client wishes to hide a few links from the navigation if they visit one URL. To explain:
domain.com : should have all links from the primary auto nav
domain2.com : should have all but two links from the primary auto nav (for purposes of example, let's say /blog, and /contact).
So, if I visit domain2.com, I see all the same content, minus "/blog" where my client wishes his blog wasn't visible to the audience arriving from a vanity domain name.
I'm thinking I can add an if/else in my default.php template that checks the inbound URL, maybe with something like HTTP_REFERER? Then maybe some CSS that hides the link based on page handle or ID? Any ideas or recommendations on how to handle this?
Thanks,
Zach
domain.com : should have all links from the primary auto nav
domain2.com : should have all but two links from the primary auto nav (for purposes of example, let's say /blog, and /contact).
So, if I visit domain2.com, I see all the same content, minus "/blog" where my client wishes his blog wasn't visible to the audience arriving from a vanity domain name.
I'm thinking I can add an if/else in my default.php template that checks the inbound URL, maybe with something like HTTP_REFERER? Then maybe some CSS that hides the link based on page handle or ID? Any ideas or recommendations on how to handle this?
Thanks,
Zach
I would use $_SERVER['SERVER_NAME'] or $_SERVER['HTTP_HOST'], and like you suggest do an if test in the default.php file. But, rather than use CSS my if test would load one of two hard coded autonav blocks, dependent on the domain name in use.
Thanks for the reply olliephillips! I think the line define('BASE_URL', 'http://domain.com'); in site.php overrides any URL that I forward to it, so I always see domain.com with the script I set up.
I use Plesk, and was going to do a frame forward from domain2.com, but even just testing with the IP address flips right over to domain.com. Any other ideas on how to handle this?
I use Plesk, and was going to do a frame forward from domain2.com, but even just testing with the IP address flips right over to domain.com. Any other ideas on how to handle this?
Yeah, that's a problem. You could try setting this in your config/site.php file:
...but I'm not sure if there are other negative side-effects to doing that -- maybe clicking links to other pages of the site will subsequently bring them to the other domain?
Another idea is to "short-circuit" the BASE_URL redirect thing by adding a rewrite rule to your .htaccess file which looks for that one domain name and appends an argument to the querystring if it's found -- so your code would look for that querystring arg instead of the domain name itself. This would also present the problem of subsequent link clicks going to the wrong domain name. Although I suppose you could set a session cookie or something.
Finally, if this is a client project and you have a budget, you might want to check out the "Domain Mapper" addon in the marketplace -- it's pricey but I believe it does what you're wanting.
define('REDIRECT_TO_BASE_URL', false);
...but I'm not sure if there are other negative side-effects to doing that -- maybe clicking links to other pages of the site will subsequently bring them to the other domain?
Another idea is to "short-circuit" the BASE_URL redirect thing by adding a rewrite rule to your .htaccess file which looks for that one domain name and appends an argument to the querystring if it's found -- so your code would look for that querystring arg instead of the domain name itself. This would also present the problem of subsequent link clicks going to the wrong domain name. Although I suppose you could set a session cookie or something.
Finally, if this is a client project and you have a budget, you might want to check out the "Domain Mapper" addon in the marketplace -- it's pricey but I believe it does what you're wanting.
Awesome, thanks for the suggestions. I've purchased the Domain Mapper and I think that's going to work out for other redirect/splash page tasks I have, but not necessarily for this nav request. I did a frame forward in Plesk, and I can grab the alternate inbound domain with HTTP_REFERER, so checking for that condition is solved. Now what to do with it...
One thing I'm considering is to set up an alternative nav. Do you have any advice on how to handle this? I could hardcode and include one, but won't get the nice auto nav features and would obviously create update headaches down the road.
I was thinking something like:
Or, I found a thread here:http://www.concrete5.org/community/forums/customizing_c5/header-nav... that suggests I could add an attribute for each page. So, I could add an "exclude from alternate nav" option. I'm still pretty new to C5 and just not sure what the best practice would be. Any ideas? Thanks in advance.
One thing I'm considering is to set up an alternative nav. Do you have any advice on how to handle this? I could hardcode and include one, but won't get the nice auto nav features and would obviously create update headaches down the road.
I was thinking something like:
if ($_SERVER['HTTP_REFERER'] == 'http://domain2.com/') { $a = new Area('Alternate Nav'); } else { $a = new Area('Header Nav'); }
Or, I found a thread here:http://www.concrete5.org/community/forums/customizing_c5/header-nav... that suggests I could add an attribute for each page. So, I could add an "exclude from alternate nav" option. I'm still pretty new to C5 and just not sure what the best practice would be. Any ideas? Thanks in advance.
Alternative navs (if I'm understanding what you want) are kind of tricky. The autonav menu's automatic-ness comes from just telling it to display part of your site that is under a certain page. But an alternative nav menu I assume means you want to pick and choose a different set of pages to show than just everything in a certain section?
This means you have two choices really:
1) Set up an alternate section of the site and tell the autonav to show pages in that section.
2) Manually tell the autonav which pages you want to be included in it.
Logically, there's no other option here -- you're either having it automatically show pages in a section of the site or you're not doing that (in which case you need to tell it which to show).
So creating a new attribute is one way to "manually choose" the pages. Another option is to use a free addon I've made called "Manual Nav" which lets you choose the pages to be included when you add the block. Note that this addon is for designers and as such it is unstyled (requires you to style it with CSS). There are other addons in the marketplace that cost money which function similarly but come with pre-set styles.
Hope that helps.
This means you have two choices really:
1) Set up an alternate section of the site and tell the autonav to show pages in that section.
2) Manually tell the autonav which pages you want to be included in it.
Logically, there's no other option here -- you're either having it automatically show pages in a section of the site or you're not doing that (in which case you need to tell it which to show).
So creating a new attribute is one way to "manually choose" the pages. Another option is to use a free addon I've made called "Manual Nav" which lets you choose the pages to be included when you add the block. Note that this addon is for designers and as such it is unstyled (requires you to style it with CSS). There are other addons in the marketplace that cost money which function similarly but come with pre-set styles.
Hope that helps.