How to create a subdomain pointing to a file/subdirectory


I need to create subdomains to point files and subdirectories:

  1. pointing to < /public_html/subdomain/ >.

  2. file, pointin to < /public_html/file.php >.

I would prefer to automate the process with an script instead of making it one by one but I would appreciate your help to make it in any of the two ways.

Thank you