简体   繁体   中英

How do I prevent a dynamic link change in PHP?

I develop in ASP.NET MVC so please forgive my lack of the basics when it comes to PHP and WordPress. We have a WordPress site where the terms and conditions link in the footer is broke on one page but works on another.

On our home page ( http://www.ourdomain.com ) there is a link and when I hover on it I can see in Chrome that it dynamically changes from:

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

to:

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

When I view the source of the page the anchor tag is like this:

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

This works fine and renders the necessary pdf file. We have another url ( http://www.ourdomain.com/contact ) that also has a terms and conditions link that changes from:

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

to:

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

When I view the source of the page the anchor tag is as follows:

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

I have access to the entire site and the MySQL database for the site. What can I change to prevent the link from adding content to the URL? Are such links usually stored in the database?

Its because you didn't enter full path so the address is countine from your page address. as you see happend with the contact

/ will point to domain base

./ or empty will point to current url

Examples example.com/contact

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

will point to http://example.com/somefolder/file.pdf

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

will point to http://example.com/contact/somefolder/file.pdf

To avoid this you can enter the full url.

In case of wordpress if the link is in your theme you can use the function get_stylesheet_directory_uri() to get the full url for your theme.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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