I have a Joomla! site set up where multiple domains are being used for one Joomla instance. The root domain for the site is www.pky.com. When visiting any other domain name on the list of names we purchased they are directed to the root domain but I am using a php script to redirect to the appropriate domain name for the "site" being viewed by testing the URI. Some of the urls used for the site are exampleone.pky.com, exampletwo.pky.com, etc.
Our redirect script in the index.php file for the site is set up like so:
<?php
$domain = $_SERVER["HTTP_HOST"];
$requri = $_SERVER['REQUEST_URI'];
if ((($domain == "pky.com") || ($domain == "www.pky.com") || ($domain == "citywestplace.pky.com") || ($domain == "www.citywestplace.pky.com") || ($domain == "gwplazahouston.com") || ($domain == "www.gwplazahouston.com") || ($domain == "greenwayplaza.pky.com") || ($domain == "www.greenwayplaza.pky.com") || ($domain == "postoakhouston.com") || ($domain == "www.postoakhouston.com") || ($domain == "postoakcentral.pky.com") || ($domain == "www.postoakcentral.pky.com") || ($domain == "sanfelipeplaza.com") || ($domain == "www.sanfelipeplaza.com") || ($domain == "sanfelipeplaza.pky.com") || ($domain == "www.sanfelipeplaza.pky.com")) && ($requri == "/index.php/citywestplace-marketing")) {
header("Status: 301 Moved Permanently");
header("Location: http://www.citywesthouston.com$requri");
}
One of our main issues is that someone entering in foo.pky.com will still show up to the site which in turn breaks the script. Is there a way to set a variable to a regex that fits all possible variations of letters, numbers, and other characters then use that variable as part of the url so that it is also redirected to the root domain?
For example:
$myvar = some regex here;
if (($domain == "pky.com") || ($domain == "www.pky.com") || ($domain == $myvar . ".pky.com") || ($domain == "www" . $myvar . ".pky.com"))...
There must be a better way to do all this but I am still learning.
Thank you in advance.
EDIT
So I have added:
if (((preg_match(`.*\.pky\.com`, $domain)) || (preg_match(`www\..*\.pky\.com`, $domain))) && ($menutype == "mainmenu")) {
header("Status: 301 Moved Permanently");
header("Location: http://www.pky.com");
}
to check if anything is being added in front of pky.com && the current menu type is "mainmenu". I checked the regex that Aziz had mentioned; however, entering:
foo.pky.com still goes to the url foo.pky.com and not redirected to pky.com.