简体   繁体   中英

How to get matching server alias (Apache 2.4 / PHP)

I have a service that I am developing actively. One very important part of logic is user id recognition from used domain. Web user arrives to address http://test.address.com (witch is alias for 1234567.address.com). Apache will serve content from document root (matching with ServerAlias).

Apache configs:

<VirtualHost *:80>
    ServerName example.address.com
    ServerAlias *.address.com
    UseCanonicalName Off
    ....
</VirtualHost>

Can I somehow detect and send matching server alias to PHP (with SetEnv or other ways)? PHP need to know address 1234567.address.com somehow. Is there a way to do that?

Yes just get it from the HTTP_HOST environment variable. No need to send, it's already passed on by Apache. Use this:

$_SERVER["HTTP_HOST"]

Ref: PHP Predefined Variables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM