How to create a subdomain pointing to a file/subdirectory

Hi,

I need to create subdomains to point files and subdirectories:

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

  2. file,example.com pointin to example.com/file.php < /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