简体   繁体   中英

PHP include seems to make page interpret itself as a directory

I have a page, index.php , like this (simplified):

<img src="content/banner.png"/>

The image loads fine. But when I include a certain (WordPress) script, like so,

<img src="content/banner.png"/>
<?php
    include('template-loader.php');
?>

the image no longer loads! I also notice the URL in the browser becomes index.php/ .

How is this possible? The image of course won't load because I'm using relative paths and it's looking for index.php/content/banner.jpg . True, I can use absolute paths to fix this issue, but I'd like to know what could be happening and how the problem might be fixed in PHP.

I'm testing on a local wamp installation and have disabled all mod_rewrite s and such, to be sure it's not something external causing the problem.

D'oh. Minutes after posting, I found the culprit, right in the script:

/**
 * Loads the correct template based on the visitor's url
 * @package WordPress
 */
if ( defined('WP_USE_THEMES') && WP_USE_THEMES )
        do_action('template_redirect');

It's doing some kind of a redirect; commenting this out makes everything work as expected.

I still don't really understand how this script can magically redirect to index.php/ as if it were a directory (and have the document actually load) but...

I will delete this question in the future if it doesn't seem to be helping anyone (based on views and votes).

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