比方說,我有/secret/example.php
在我的.htaccess檔案我想請求重寫/secret到/home.html使用
RewriteRule secret /home.html
但是現在當我嘗試/secret/example.php使用 ajax訪問時example.js
var xhr = new XMLHttpRequest();
xhr.open('GET', '/secret/example.php', true);
xhr.onload = function(){
console.log(xhr.responseText);
}
xhr.send();
它也被重定向并且不起作用。
有沒有辦法我只能重寫用戶發出的請求(通過www.example.com/secret在搜索欄中鍵入)并仍然允許 ajax 訪問檔案?
uj5u.com熱心網友回復:
如果您在 xhr 請求中設定附加標頭,則是可能的: xhr.setRequestHeader("VIAXHR", "true");
然后在 .htaccess 中是這樣的:
RewriteCond %{HTTP:VIAXHR} !^true$
RewriteRule secret /home.html
uj5u.com熱心網友回復:
在 RewriteRule 之前使用 RewriteCond
重寫條件檔案
像這樣的東西:
RewriteCond %{REQUEST_URI} !^/secret/example.php$
RewriteRule secret /home.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/403319.html
標籤:
上一篇:.htaccess需要幫助來處理對非根檔案夾中的index.php的請求
下一篇:FlutterWeb404未找到
