简体   繁体   English

PDF 链接转到“无法获取文件”并出现 404 错误

[英]PDF link goes to “Cannot GET file” with a 404 error

Trying to have a link open up to a PDF.试图打开一个指向 PDF 的链接。 I have the href="filename.pdf" - the pdf file is in the same folder as the html file.我有 href="filename.pdf" - pdf 文件与 html 文件位于同一文件夹中。 When I click on the link it opens to a new page (I have it set to open a new page) which says "Cannot GET /filename.pdf".当我单击链接时,它会打开一个新页面(我将其设置为打开一个新页面),上面写着“无法获取 /filename.pdf”。 I open the console and it says "Failed to load resource: the server responded with a status of 404 (Not Found)".我打开控制台,它显示“加载资源失败:服务器响应状态为 404(未找到)”。

I found a solution that works but I don't understand why: This doesn't work:我找到了一个可行的解决方案,但我不明白为什么:这不起作用:

<a target="_blank" class="cta-btn cta-btn--resume" href="connerschiller.pdf">View Resume</a>

But this does work:但这确实有效:

<a target="_blank" class="cta-btn cta-btn--resume" href="../src/connerschiller.pdf">View Resume</a>

The html file is in the src folder as well. html 文件也在 src 文件夹中。

Ok so the fix I listed above is working when I run it locally, but when I try to open the PDF link on the deployed site on netlify it says "Page Not Found Looks like you've followed a broken link or entered a URL that doesn't exist on this site."好的,所以当我在本地运行它时,上面列出的修复程序正在工作,但是当我尝试在 netlify 上的已部署站点上打开 PDF 链接时,它显示“找不到页面看起来你已经点击了一个损坏的链接或输入了一个 URL这个网站上不存在。”

If the file is in the same directory you need to use as follows:如果文件在同一目录中,则需要按如下方式使用:

<a href="./filename.pdf">My pdf</a>

the./ is to especify the same directory ./ 是指定同一个目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM