开发者

how to use subdomain name as a variable (with .htaccess?)

开发者 https://www.devze.com 2023-02-17 04:39 出处:网络
i want to have several subdomains for my CakePHP application, like http://app1.mydomain.com, http://app2.mydomain.com,

i want to have several subdomains for my CakePHP application, like

http://app1.mydomain.com, http://app2.mydomain.com, http://app3.mydomain.com, ht开发者_StackOverflow中文版tp://app4.mydomain.com, etc.

how can i use app1, app2, app3, etc, as variables in my application (ie. every subdomain will have unique design)?

is it possible to "parse" url with .htaccess, or it's better to use php functions to achieve that?

tnx in adv!


You don't need any .htaccess rules for this. You can simply determine it in PHP with:

$subdomain = strtok($_SERVER["HTTP_HOST"], ".");

Take care that this is a user-supplied value. (Apache only whitelists the first level vhosts.)


Create Subdomains on the fly with .htaccess (PHP) Create subdomains on the fly with .htaccess (PHP)

0

精彩评论

暂无评论...
验证码 换一张
取 消