I'm attempting to create a unique series of redirects on an Apache web server (Server version: Apache/2.2.15). Using .htaccess or additional Apache modules, I need to fully parse requested URLs in order to extract hostnames without the standard .com suffix.
Example:
I need vendorname from the hostname vendorname.com.
The business I'm supporting works with third-party vendors and has created unique top-level domains for each of them that points to a vendor-specific sub-directory in the document root of the web server.
Example:
vendorname.com/logo.jpg loads an asset that can also be accessed at parentbusinessdomain.com/vendorname/logo.jpg
This convention was put into place by the business 10 or 15 years ago and there are many, many vendors. What the business didn't account for was the need to support HTTPS/SSL implementation for each unique domain. Had they gone with sub-domains such as vendorname.parentbusinessdomain.com then this would have been a non-issue. Going forward, we wish to abandon this convention and simply host images and other assets from https://parentbusinessdomain.com.
The problem I'm continuously running into is that there doesn't seem to be a standard Apache string operation or server-side variable which represents or extracts the hostname without the specific string ".com". This sort of string extraction is feasible with backend PHP or frontend Javascript but it appears that I'm limited with what .htaccess itself can do.
Similar example with custom Javascript function: https://stackoverflow.com/a/16934798/602514
parseURL('https://www.facebook.com/100003379429021_356001651189146');
Result:
Object {
domain : "www.facebook.com",
host : "facebook",
path : "100003379429021_356001651189146",
protocol : "https",
subdomain : "www",
tld : "com"
}
The contingency will be to explore URL rewrite/redirects within the legacy web application itself but hoping there may be a more elegant solution from an infrastructure perspective.