ajax and php directories


ajax and php directories

  • 我有一个目录,让我们称之为它,dir1我有一个 html 文件,它叫做 index.html 并且我在同一个目录中.htaccess将所有 url 路由到 index.html 的文件。
  • 我还有一个dir1的 dirctory,dir2它有一个名为 index.php 的 php 文件。
  • index.html向 ajax index.php发送请求,当 URL 被localhost/dir1/时,请求可以正常工作,或者也可以使用 localhost/dir1/index.htmllocalhost/dir1/anything_here,因为 .htaccess 文件在 url 被localhost/dir1/anything/它不能正常工作时,或者当 URL 被localhost/dir1/anything/anything/any../..时,它不能正常工作等。

这个问题的解决方案是什么?

解决方案是使用绝对 URL 而不是相对 URL。因此,基本上,请求应该针对/path/to/the/php/file.php而不是path/to/...

您可以在head部分中使用 base 标签:

<head>
  <base href="http://url.com/dir1/">
</head>