我有一個特定的網(wǎng)頁。這是文件結(jié)構(gòu):index.phpscript.jsstyle.cssedit | |--- index.php | |--- script.jsedit/index.phpindex.php正在呼應(yīng)using file_get_contents('../index.php')which contains的內(nèi)容<script src='script.js'></script>。edit/script.js包含alert(). 當(dāng)我打開時https://www.example.com/edit,它顯示 的內(nèi)容index.php,但不執(zhí)行里面的代碼edit/script.js。為什么會發(fā)生這種情況?我該如何解決這個問題?(雖然index.php有擴展名,但.php它不包含任何 PHP,只包含 HTML)
1 回答

慕妹3146593
TA貢獻1820條經(jīng)驗 獲得超9個贊
問題是瀏覽器不知道這edit
實際上是edit/index.php
. 它認(rèn)為這是根目錄中的文件,因此在解析時script.js
它也會在根目錄中查找該文件。
edit
您應(yīng)該配置網(wǎng)絡(luò)服務(wù)器,以便它執(zhí)行從到 的重定向edit/index.php
,而不僅僅是返回 的內(nèi)容edit/index.php
。這樣,所有相對 URL 都將被正確處理。如果您不想顯示腳本名稱,您可以重定向到edit/
——這足以讓它知道這是一個目錄而不是文件。
- 1 回答
- 0 關(guān)注
- 129 瀏覽
添加回答
舉報
0/150
提交
取消