E.g. My site have two subdomains : domain_a and domain_b.
I create a path: "custom/a".
domain_a can visit the path.
domain_b visit the path, get 404.
Except according to the
golbal $domain in the code, does anyone have other solution?
Then you can just add a selection rule or access control rule to specify the valid domains via the user interface.
Alternatively, you could do something with hook_menu access callbacks.