us-er8192
us-er8192

Reputation: 11

image path not working when accessing php include file from two different folders

I have included a 'header' file in files which are in root folder and the header file is in 'inc' folder. header.php is completely working when accessing from subdomain/main-website/index.php file. But when accessing from subdomain/index.php, only the logo is not showing due to the relative path.

Folder Structure: subdomain/main-website

subdomain

header.php

<div>
 <img class="logoImg" src="img/logo.png" alt="" title="" />
</div>

<nav id="nav-menu-container">
 <ul class="nav-menu">
  <li class="menu-active"><a href="index.php">Home</a></li>
  <li><a href="about-us.php">About Us</a></li>
 </ul>
</nav>

So what should be done or what is the best approach for this.

Upvotes: 1

Views: 94

Answers (2)

Ajowi
Ajowi

Reputation: 505

You can always anchor yourself on the root folder by using ../path-to-sub-folder/. Accordingly, you must then give the folder names starting from this root - base excluded. This should work as long as base directory carries all your sub-domains. But as a last resort, and NOT for public-facing links, you can refer to absolute file reference like /var/www/html/base_folder/sub_folder/.

Upvotes: 0

ArkDevLarry
ArkDevLarry

Reputation: 54

Use absolute path for the image https://your.subdomain.com/main-website/img/logo.png. I hope this helps.

Upvotes: 1

Related Questions