私が正しければ、ワイルドカードを使用ServerAlias
して mod_rewrite を使用すると、適切なファイルに書き換えて、仮想ホストが次のようになります
<VirtualHost *:80>
ServerName mysaasapp.com
ServerAlias *.mysaasapp.com
DocumentRoot /var/www/user
</VirtualHost>
あなたのCNAMEは次のようになります
*.mysaasapp.com IN CNAME mysaasapp.com
これが役立つことを願っています
編集:
仮想ホストをに変更します
<VirtualHost *:80>
ServerName mysaasapp.com
ServerAlias *.mysaasapp.com
DocumentRoot [STANDARDFOLDER]
</VirtualHost>
mysaasapp.com[STANDARDFOLDER]
のに置き換えます。DocumentRoot
index.php
そして一番上のあなたの場所にこれ:
// Array with all the subdomains who doesn't belong to users
$_notUsers = array("www");
// No code without a Boom,
$_domainParts = explode('.',$_SERVER[HTTP_HOST],-2);
// Check if subdomain is legit
if(!in_array($_domainParts[0],$_notUsers) && !empty($_domainParts)){
// get the real subdomain structure
$_sub = str_replace('.mysaasapp.com','',$_SERVER['HTTP_HOST']);
// Don't look at this it's horrible :'( but this makes it think that there is
// something in user
$_GET['user'] = $_sub;
// I dont know where you want it in the question its index.php and in comment its
// user.php so change this as you want it
include 'user.php';
// Exit so we dont have an user page and homepage together but only when
// using user.php comment this out when using index.php
exit;
// end
}
これはあなたの問題に対する本当に汚い解決策です。今はうまくいくことを願っています
アップデート:
最初は、あなたがカスタム ドメインからもリダイレクトすることを望んでいるとは知りませんでした。
次に、DNSサーバー/マネージャーにCNAMEを追加する必要があります
theirdomain.com IN CNAME thierusername.mysaasapp.com
DNSレコードがすべてのサブドメインがApacheに送信されるようになっている場合、Apacheはコードと私が提供したVhostsで動作する必要があります
更新 2:
lanzz は私が忘れていたことを指摘しました (facepalm) HOST ヘッダーをチェックしていますが、意味がないcustomdomain.com
ので、ユーザーにドメインを尋ねる必要があります (共有 IP を持っていない場合は、CNAME を指定させてください。共有 IP を持っていない場合は、A レコードを使用して IP を指すようにすることができます)、HTTP_HOST からドメインを検索し、データベースでそれを検索すると、動作するはずです!
少し編集したコード:
//first look if you're on your own domain,
// also again an Array with all the subdomains who doesn't belong to users
$_notUsers = array("www");
//lets explode the domain
$_domainParts = explode(".",$_SERVER["HTTP_HOST"]);
//get length of $_domainParts
$_domainPartsLength = count($_domainParts);
//get last two parts (little bit ugly but there are uglier ways)
$_currentDomain = $_domainParts[$_domainPartsLength-1] . "." . $_domainParts[$_domainPartsLength-2];
//time to check if it's yours and if it's legit
if($_currentDomain == "mysaasapp.com"){
if(!in_array($_domainParts[0],$_notUsers) && !empty($_domainParts)){
// get the real subdomain structure
$_sub = str_replace('.mysaasapp.com','',$_SERVER['HTTP_HOST']);
// Don't look at this it's horrible :'( but this makes it think that there is
// something in user
$_GET['user'] = $_sub;
// I dont know where you want it in the question its index.php and in comment
// its user.php so change this as you want it
include 'user.php';
// Exit so we dont have an user page and homepage together but only when
// using user.php comment this out when using index.php
exit;
}
// here is your standard index (sorry for the odd placing)
}else{
//now here are we gonna play with the custom domain
// this function should return the username if the hostname is found in the
// database other wise it should return false
$_user = userGetByDomain($_SERVER["HTTP_HOST"]);
if($_user === false){
// tell the browser its not legit
header("Status: 404 Not Found");
//show your 404 page
include '404.php';
// and die
exit;
}
// now we know everything is okay we are gonna do the same thing as above
$_GET['user'] = $_user;
// I dont know where you want it in the question its index.php and in comment
// its user.php so change this as you want it
include 'user.php';
// Exit so we dont have an user page and homepage together but only when
// using user.php comment this out when using index.php
exit;
}