- 我有一个目录,让我们称之为它,
dir1
我有一个 html 文件,它叫做index.html
并且我在同一个目录中.htaccess
将所有 url 路由到index.html
的文件。 - 我还有一个
dir1
的 dirctory,dir2
它有一个名为index.php
的 php 文件。 -
index.html
向 ajaxindex.php
发送请求,当 URL 被localhost/dir1/
时,请求可以正常工作,或者也可以使用localhost/dir1/index.html
或localhost/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>