【问题标题】:How to make link working in localhost/html如何使链接在 localhost/html 中工作
【发布时间】:2014-11-15 08:50:05
【问题描述】:

我的电脑中有一个 pdf 文档,位于 c:/xampp/htdocs/test.pdf

我已经链接了这个文件(点击这里) 在文件 nav.html 中,该文件也保存在 htdocs 中。

当我通过在地址栏中键入 localhost/nav.html 打开此文件时,链接不起作用。但是如果我通过在文件 nav.html 中双击它来打开它(在这种情况下,地址栏显示 file:///C:/xampp/htdocs/nav.html ),则链接有效。

如何在前一种情况下使链接处于活动状态。

【问题讨论】:

  • 很可能 Apache 没有运行或配置为侦听非标准端口(不是端口 80)
  • 您的 apache 服务器是否正在运行..(wamp 或 xampp 或其他)?
  • 你是怎么链接的?

标签: html url


【解决方案1】:
  • 使用相对路径<a href="test.pdf" title="pdf">( click here )</a>

  • 确保test.pdf文件和nav.html位于同一文件夹c:/xampp/htdocs/

  • 如果您的页面 nav.html 未使用 localhost/nav.html 加载,那么您必须检查 apache 服务状态并测试端口 80

  • 在文件 c:\XAMPP\apache\conf\httpd.conf 中检查您的文档根目录

    DocumentRoot c:/users/farshad/documents/web/
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    
    <Directory c:/users/farshad/documents/web/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>
    

正如@Monsieur Tino 建议的那样

【讨论】:

    【解决方案2】:

    哦, 尝试从另一台计算机连接,然后转到您的服务器链接(例如 192.168.1.XX 将 XX 替换为您的路由器所分配的号码)。然后,测试您是否可以转到您的pdf。如果它不起作用,请尝试(我猜你的 DocumentRoot 是 C://xammp):

    <a href="/htdocs/test.pdf" title="test">Behind this link, there's a pdf</a>
    

    【讨论】:

    • 这行不通。web 根目录位于/htdocs/ 你必须使用@Farshad 建议的相对路径或使用http://localhost/test.pdf
    • 对不起,我在我的服务器上使用 Debian,不知道它在 Windows 上是如何工作的。
    猜你喜欢
    • 1970-01-01
    • 2010-09-30
    • 1970-01-01
    • 2014-04-14
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多