Virtual domain redirect

Virtual domain redirect

I'm building a new school site. I'm trying to condense several sites as I do this so I am also contending with multiple domains. Think this: district.schools school1.schools school2.schools school2.schools facilities.schools.

Each site is made up of two templates. A home template and an article template. Each site has its own category. The district.schools with also have multiple categories. They all have to work with one another such as some writes an category article of Technology can tag it as a school2 and school3 related. That article will show up on the school2 and school3 site with a link.

Right now, I have two rules to make this work. The first rule is if the category is school1 and we are in the environment of district.schools,school2.schools,school3.schools,facilities.schools then redirect as permanent 301 to http://school1.schools/{path}. Then a second rule after that one that if it is a school1 article, set TemplateStyle to school1 - article template.

This works but raises a red flag with me concerning the first rule. There will be neumerous domains and I am also worried some departments will suddenly want their own domain. Each time someone changes their mind, each rule 1 has to be modified for the new domain. I am wondering if there is an easier way to do this or a way to declare 'Exclude Domain' instead of specifying every domain?

I have tried not setting the environment but it causes multiple redirects once the first redirect to the proper domain has been done. Which makes sense.

I am using the Virtual Domains component to set the home page templates.

Re: Virtual domain redirect

this is a great question and shows you're thinking carefully about the issues involved.

Apart from me adding an "exclude these domains" control (which is admittedly pretty easy to add), you can achieve the same thing using a snippet of PHP in the PHP tab:

if ($core_genius->check("domain not = school1.schools")) return true;

If you use that, you don't need to use the box in the Environment tab.

Potentially, if you are comfortable with using some PHP like this, you might actually be able to set up the entire group of rules in just 1 rule, which could make adding new schools/departments a lot easier since there would be just 1 place to edit.

It's going to depend a little on exactly what you want to achieve, but I wonder about something like this:

Then in the Succeed action, you can do a redirect to http://{global:$my_redirect_domain}/whatever, probably using the other special replacement tokens to redirect to the same page on the other domain.

You'll still need a second rule to detect the different article pages and set the domain names for them. Even for that you might be able to use a PHP based rule to make it easier to handle multiple domains and future additions.

How does that sound?

Stephen BrandonMetaMod / Chameleon developerIf you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

Re: Virtual domain redirect

The if ($core_genius->check("domain not = school1.schools")) return true; is exactly what I was looking for. As far as the 1 rule for all of them, I start to run into some problems. First, not all departments will have their own domain. Technology and Food Services with still be under school.schools. I can add both into the array so they are there. I tried that and either they are just staying on school.schools instead of becoming school1.schools (for the school redirects) or the {global:$my_redirect_domain} just becomes http://%7bglobal:$my_redirect_domain%7D.

Re: Virtual domain redirect

Hi,

if the {global} replacement isn't working, then you're not using the most up to date version of Chameleon. Log in to this site to download the most recent version which you can simply install over top of the old version to update it.

With regard to the "not all departments will have their own domain" issue, I'm not 100% following what you're trying to achieve here (sorry). Can you please explain that a little further, with an example of exactly what you want to happen?

Thanks,
Stephen

Stephen BrandonMetaMod / Chameleon developerIf you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

Re: Virtual domain redirect

Sorry I just read the first paragraph. It's not only the Schools that will have pages but also departments. The departments have their own category as well but not a domain. I decided to add each department as well just in case a person clicks on an athletics article from the elementary school, they would go back to the school.schools domain. This is an example of the breakdown of the rule.

Re: Virtual domain redirect

Well. It kinda worked. When you are on school.schools domain and click on an article which falls under the "school3.schools"=>"High School", rule, it works and changes the domain and shows the article. If you go to the school3.schools domain and click on the same article, you then get the too many redirects error again.

Re: Virtual domain redirect

Hi,

I think my head is spinning a little... :-Z as I'm struggling to understand exactly how you want this to work. I know, it's complex! And we'll get there. This sort of thing is what Chameleon is designed for, so it's a matter to translating what you want to happen into appropriate rules.

One thing with arrays is that the first item in team pair needs to be unique. Since you have a situation where 1 school can map to more than 1 category, we have to restructure the array.

We also need to put in another test to ensure we don't redirect back to the same domain and page that we just came from. I'm not sure if I have enough info at the moment to fashion a rule for that, but can make a start on it. It would also help to have some actual exact examples of URLs, if you're happy to post them up here (or put them in a PM to me).

So here's another way of structuring the code I wrote before, taking into account that one domain can map to several categories. One key difference is that it should only trigger the redirect if the user is NOT already on the domain given. That's different from what I wrote last time (which was probably wrong... sorry).

// this matches the domain name to certain categories. It outlines which domain
// (the 1st item) should be used for which categories.
// If a category is on more than one domain (below) then only the 1st one will
// be used.
$domains = array(
"school1.schools"=>array("Elementary School"),
"school2.schools"=>array("Middle School"),
"school3.schools"=>array("High School"),
"llc.schools"=>array("LLC"),
"school.schools"=>array("School Department", "Athletics", "Nursing", "Technology") // last item does not end in comma
);
foreach ($domains as $domain=>$cat) {
// check that we're NOT on the given domain but ARE on the given
// category: if so then redirect to the given domain.
if ($core_genius->check("domain != ", $domain) and $content_genius->check("category_title = any of ", $cat)) {
global $my_redirect_domain;
$my_redirect_domain = $domain;
return true;
}
}

Stephen BrandonMetaMod / Chameleon developerIf you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

Re: Virtual domain redirect

Here is the posted rule I just put in with the current domains I am currently working on. There will be changes when the site eventually goes live since it is replacing sever different websites.

// this matches the domain name to certain categories. It outlines which domain
// (the 1st item) should be used for which categories.
// If a category is on more than one domain (below) then only the 1st one will
// be used.
$domains = array(
"pondcove.cape.k12.me.us"=>array("Pond Cove Elementary"),
"cems.cape.k12.me.us"=>array("Middle School"),
"cehs.cape.k12.me.us"=>array("High School"),
"joomla.cape.k12.me.us"=>array("Cape Elizabeth School Department", "Athletics","Authorfest", "Business Office", "Facilities", "Food Services", "Insight", "Instructional Services", "LLC", "Nursing", "Technology") // last item does not end in comma
);
foreach ($domains as $domain=>$cat) {
// check that we're NOT on the given domain but ARE on the given
// category: if so then redirect to the given domain.
if ($core_genius->check("domain != ", $domain) and $content_genius->check("category_title = any of ", $cat)) {
global $my_redirect_domain;
$my_redirect_domain = $domain;
return true;
}
}

Re: Virtual domain redirect

With this, The redirect doesn't happen at all, which is both a good and a bad thing. Before this new rule, I would click on a "Pond Cove Elementary" article that was listed on the front page of the joomla.cape.k12.me.us site and it would change the domain to http://pond cove.cape.k12.me.us/path/to/article. Great, but if i was already on the pondcove.cape.k12.me.us site and click on the article, it would give me redirect errors. So you were spot on with what you did understand.

So, now with the new rule, I click on the article from the joomla.cape.k12.me.us site and the article pops up with the correct template (I have an additional rule for each different category bringing it to the correct article template) but it doesn't change domains. If I am already on the pondcove.cape.k12.me.us domain, the article comes up with the correct domain. Course that might just be that the rule failed anyway.