PHP - 如何在MVC项目的Javascript文件中请求它时隐藏Ajax目录?

I'm writing a MVC project. I have two directories. First one is public. Everybody can reach this directory. It contains index, javascripts, css etc... Second one contains application files. This directory is forbidden from normal users, and ajax files are contained here(in the controllers folder). When I use ajax php files in javascript, I have to use something like "application/controllers/ajax/file.php". The problem is, I don't want to expose my directory. I want to hide it like "ajax/file.php". What can I do about it?

You could use mvc server side too (but a php one like symfony, laravel, etc.) or at least make a routing system in your ajax/file.php then you ajax call will hide the real path of the file which will do operations.

ALTERNATE: You can create a function in controller and you can use route.

class A {
  function ajax() {
    // return data
  }
}

Use route and call it as http://example.com/A/ajax I hope you got it.