Referrer URL 中間經過 轉址(301、302 Redirect), 到底會帶到的是哪個 URL 呢?
關於 Referrer URL 的幾項測試
a.html 透過 b.php 轉址到 c.php (於 c.php 印出 Referrer)
a.html 內容
<a href="b.php">b</a>
c.php 內容
<script> alert(document.referrer); </script> <?php echo $_SERVER['HTTP_REFERER']; ?>
測試項目 (b.php, 用下述三種方式分別測試)
- HTML refresh 轉址
<meta http-equiv="refresh" content="0;url=http://example.com/c.php">
- PHP Header Location 轉址
<?php header('Location: http://example.com/c.php'); ?>
- HTML 透過 JavaScript 轉址
<body onLoad="javascript:window.location='http://example.com/c.php'"></body>
結果
- HTML refresh 轉址 Referrer URL: a.php
- PHP Header Location 轉址 Referrer URL: a.php
- HTML 透過 JavaScript 轉址 Referrer URL: b.php
相關網頁
- Protecting Privacy with Referrers (Facebook) - 這篇有詳細各種瀏覽器的測試、比較表, 推薦必看
- analytics - How can I pass referrer header from my https domain to http domains? - Webmasters Stack Exchange
- How to keep referrer? Apache Web Server forum at WebmasterWorld
- How Google Analytics handles 301 and 302 Redirects - THIS IS AN ANSWER