Skip to content

[已解決] Not Acceptable! An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.

當我使用程式請求存取我的 WordPress 網站時,伺服器返回了以下這樣訊息。

Not Acceptable!
An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.


根據錯誤訊息的提示,我們可以假設此錯誤可能是下列兩種情形:

  • 伺服器找不到我們請求資源時所使用的格式,所以無法接受這種請求
  • 伺服器的 Mod_Security 認為該請求可能是惡意攻擊

目前經過嘗試,能解決的辦法應有下面 3 種:

  • 清除 Cookie/Cache(僅限網頁瀏覽時發生此問題
  • 在請求程式碼中加入 user-agent 以及content-type
  • 修改 .htaccess 文件(需確認自己能成功復原

解決方法

方法一: 清除瀏覽器的 Cookie/Cache

有一種被封鎖的情況是,當你反覆輸入錯誤的帳號密碼時,伺服器端的安全防護認定你所使用的瀏覽器/IP 地址為惡意攻擊來源,於是將瀏覽器資訊、IP 位置等資訊封鎖。

這種情況下,可以嘗試將瀏覽器的 Cookie/Cache 資料清除,重新嘗試請求。


方法二: 在請求程式碼中加入 user-agent 以及 content-type

  • user-agent 字串適用於確認用端資訊的欄位,比方說瀏覽器版本號以及作業系統,也是反爬蟲時可能會確認的欄位
  • content-type 則是設定資源請求的格式,讓伺服器知道我們要請求的格式,以防被伺服器因無法確認格式而拒絕


方法三: 修改 .htaccess 文件關閉 Mod_Security(不推薦,請僅止於確認問題所在)

再次提醒:請確認自己能隨時恢復文件原本的內容。

簡單來說,便是在 .htaccess 文件中,將 Mod_Security 設置為不啟用。

<IfModule mod_security.c>
  SecFilterEngine Off
  SecFilterScanPOST Off
</IfModule>

References


Read More

Tags:

Leave a Reply