如何防止PHP中的动态链接更改?

如何防止PHP中的动态链接更改?

问题描述:

我在ASP.NET MVC中开发,所以请原谅我缺乏PHP和WordPress的基础知识。我们有一个WordPress网站,页脚中的条款和条件链接在一页上打破,但在另一页上打开。如何防止PHP中的动态链接更改?

在我们的主页(http://www.ourdomain.com)有一个链接,当我将鼠标悬停在上面,我可以在Chrome中看到,它动态地改变:

ourdomain.com/wp-content/themes/mm/pdf/ Terms.pdf

到:

www.ourdomain.com/wp-content/themes/mm/pdf/Terms.pdf

当我查看网页源的锚标记是这样的:

<a href="wp-content/themes/mm/pdf/Terms.pdf">Terms</a> 

这工作正常,并呈现必要的pdf文件。我们有另一个URL(http://www.ourdomain.com/contact)也有条款和条件联系起来,从改变:

ourdomain.com/contact/wp-content/themes/mm/pdf/Terms.pdf

到:

www.ourdomain.com/contact/wp-content/themes/mm/pdf/Terms.pdf

当我观看页的源的锚定标记如下:

<a href="wp-content/themes/mm/pdf/Terms.pdf">Terms</a> 

我可以访问整个站点和该站点的MySQL数据库。我可以更改哪些内容以防止链接将内容添加到URL中?这样的链接通常存储在数据库中吗?

因为您没有输入完整路径,所以地址是从您的页面地址开始计数的。正如所看到的与接触happend

/将指向域基

./将指向当前URL

实例example.com/contact

<a href="/somefolder/file.pdf"> 

将指向http://example.com/somefolder/file.pdf

<a href="./somefolder/file.pdf"> 

将指向http://example.com/contact/somefolder/file.pdf

为了避免这种情况,你可以输入完整的网址。

如果WordPress的情况下,如果链接是在你的主题,你可以使用功能get_stylesheet_directory_uri()获得您的主题的完整url。

<a href="<?php echo get_stylesheet_directory_uri(); ?>/pdf/Terms.pdf">Terms</a>