2016-06-07 47 views

回答

0

我找到了一種方法。刪除先file.pdf並創建一個文件名爲先file.pdf.html與內容:

<script type="text/javascript"> 
document.location = "/the-second-file.pdf" 
</script> 
1

的替代(和稍好IMO)的方式來做到這將是模仿什麼jekyll-redirect確實使用meta http-equiv="refresh"標籤要求瀏覽器重定向用戶,而不需要JavaScript。

即你會刪除the-first-file.pdf並創建一個名爲the-first-file.pdf.html,內容如下文件:

<!DOCTYPE html> 
<meta charset="utf-8"> 
<title>Redirecting...</title> 
<link rel="canonical" href="https://my-site.com/the-second-file.pdf"> 
<meta http-equiv="refresh" content="0; url=https://my-site.com/the-second-file.pdf"> 
<h1>Redirecting...</h1> 
<a href="https://my-site.com/the-second-file.pdf">Click here if you are not redirected.</a> 
<script>location="https://my-site.com/the-second-file.pdf"</script> 

更妙的是,你可以利用該傑奇是生成此文件,並使用現場變量構造URL基於配置設置(當然,您也可以在您的javascript版本中執行此操作):

--- 
--- 
<!DOCTYPE html> 
<meta charset="utf-8"> 
<title>Redirecting...</title> 
{% assign redirect_url = "/the-second-file.pdf" | prepend: site.baseurl | prepend: site.url %} 
<link rel="canonical" href="{{ redirect_url }}"> 
<meta http-equiv="refresh" content="0; url={{ redirect_url }}"> 
<h1>Redirecting...</h1> 
<a href="{{ redirect_url }}">Click here if you are not redirected.</a> 
<script>location="{{ redirect_url }}"</script>