首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用github-pages从pdf文件重定向?

如何使用github-pages从pdf文件重定向?
EN

Stack Overflow用户
提问于 2016-06-08 00:10:44
回答 2查看 556关注 0票数 3

我正在尝试从一个pdf文件重定向到另一个。所以,举个例子:

代码语言:javascript
复制
https://my-site.com/the-first-file.pdf

应重定向到

代码语言:javascript
复制
https://my-site.com/the-second-file.pdf

我在重定向上查看了github's documentation,但我不能将元数据添加到pdf文件中……

感谢任何人的帮助!

EN

回答 2

Stack Overflow用户

发布于 2016-06-14 07:09:00

一种替代的(也是稍微好一点的)方法是模仿jekyll-redirect所做的事情,使用meta http-equiv="refresh"标签来请求浏览器重定向用户,这不需要javascript。

例如,您将删除the-first-file.pdf并创建一个名为the-first-file.pdf.html的文件,其中包含以下内容:

代码语言:javascript
复制
<!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>

更好的是,您可以利用Jekyll生成此文件的优势,并使用站点变量根据配置设置构造URL (当然,您也可以在javascript版本中执行此操作):

代码语言: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>
票数 3
EN

Stack Overflow用户

发布于 2016-06-10 03:14:09

我找到了一个方法。删除-first-file.pdf并创建名为-first-file.pdf.html的文件,其内容为:

代码语言:javascript
复制
<script type="text/javascript">
 document.location = "/the-second-file.pdf"
</script>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37684319

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档