Reputation: 11
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
<?php include_once 'inc/header.php'?>
)<?php include_once 'inc/header.php'?>
)subdomain
<?php include_once 'main-website/inc/header.php'?>
)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
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
Reputation: 54
Use absolute path for the image https://your.subdomain.com/main-website/img/logo.png
. I hope this helps.
Upvotes: 1