爲了節省服務器存儲空間和提升服務器網絡性能,我們往往把比較大的資源放在其他服務器,例如我們博客中使用的圖片以及文件等,但是這樣會造成一個問題,就是外鏈資源403無法正常加載,在此記錄下解決過程。
測試代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<img src="https://upload-images.jianshu.io/upload_images/5174117-82782c36f21266ee.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp" alt="測試圖片" />
</body>
</html>
顯示:
修改後的代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="referrer" content="no-referrer" />
<title>Test</title>
</head>
<body>
<img src="https://upload-images.jianshu.io/upload_images/5174117-82782c36f21266ee.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp" alt="測試圖片" />
</body>
</html>
用了最簡單方式,屏蔽自己網站的Referrer,在head標籤內添加如下mata標籤:
<meta name="referrer" content="no-referrer" />
第三方博客需要修改源文件,以wordpress爲例,修改wp-content/themes/主題名稱/framework/templates/header.php,增加mata標籤: