0

I am suffering a serious problem: after a long time I decided I am not able to solve this horrible problem and shall look for help somewhere. Here is what I want to ask.

Lets say I am running a webiste: xyx.com ( apache , php , mysql ) All page same .php no html.

No I have folder structure like this / : root , /abc : another folder in root: both root and /abc has php page which include header and footer. Header and footer contains some url like home , services , about us etc.

So I had to copy same header and footer with its images folder in both root and /abc so that It works. Now I have problem whenever I have to change something I have to change in both place. Problem is not really two folders If I have to make more folder then I will be doomed to make small change I have to change every place. Now If I make one common header and footer and use include() , then I am facing problem Since header includes css , javascript and from the /abc folder path will be different lets say even if I manage this by php using if condition still it will not work cuz css has itself so many images as style. Now I can't change css since it will be a problem, I don't want two version of css which will somehoe affect loading time. I am already putting heavy load on website which gives me average load time of 6 seconds which is too slow. I hope i was able to convey you guys whoever read this post. If not then please post query I will reply you.

Thanks a trillion :)

Now my problem is I want to have one common header and footer

I have one header and one foot

1 Answers1

2

The answer is to use absolute URLs. include the files like you said, and refer to the Javascript/CSS/etc. files with absolute URLs. Here's what your header might look like:

<html>
    <head>
        <title>Foo Bar</title>
        <link rel="stylesheet" href="/path/to/stylesheet.css" />
        <script src="/path/to/script.js"></script>
    </head>
    <body>
        ...

Notice all of the URLs start with a forward slash. This means that those paths are absolute, or relative to the root. You can include it on any page in any directory, and they will always load properly.

Jonah
  • 9,991
  • 5
  • 45
  • 79
  • Wholly agree on the suggestion (+1d). Just a word of caution, since absolute URLs are also called those referred with their FQDN and then the full server path (IE http://www.example.com/scripts/script.js). Unless you have good reasons to do so, it's wise to just keep paths relative to your server's document root. What Jonah suggested, basically. But hopefully this can help you if you're stuck with ambiguity of terms from other sources. – maraspin Aug 22 '11 at 01:51
  • @maraspin: ah yes, good clarification. "Absolute" relative to the HTTP path, not the server filesystem. – Jonah Aug 22 '11 at 01:54
  • If I am not wrong please correct me. I have to change like this. Where ever there is url like about us , contact us , I have to make it absoulute url like abc.com/aboutus.ph , abc.com/contactus.php , in css I have to use absolute path wherever it has image I will change it to the absolute path as you said. Well some how I can make it relative to root directory path. I was concern about the loading time as absolute url would mean more http request. But anyhow as there are few url so I don't have to worry about it. thanks – jam_smutha Aug 22 '11 at 01:54
  • @jam: For page links, just use absolute URLs like as illustrated for CSS files. You don't need to include the domain name. And there isn't any concern with using absolute URLs performance-wise. Unless you're loading a file with PHP, there are no extra HTTP requests. – Jonah Aug 22 '11 at 02:00
  • @Jonah , thanks I will give a try if I will have any query I will post again. – jam_smutha Aug 22 '11 at 02:06
  • Hi, there I got another problem. See I have local server where we do some change and then update it on remote server. Now local server is on xampp which is root and hence we have this website on local server which is not in root directory now whenever I gave absolute path it interpreted wrong link.. of contactus.php , aboutus.php is there any way to get out of it.. cuz I dont want to have this problem too – jam_smutha Aug 22 '11 at 16:02
  • my bad.. what I mean was on local server same folder is not in root where as on remote it is.. so is there any way.. so that I can change root path for this website only on local server only.. cuz if I change root path in .htaccess or php.conf it will change root path for each website that I have on local website and also I cant open xampp which I use for mysql managment. – jam_smutha Aug 22 '11 at 16:08
  • @jam: I recommend setting up a secondary virtualhost for testing websites. I blogged about it recently, see here: http://nucleussystems.com/blog/sub-domain-wamp-localhost – Jonah Aug 23 '11 at 01:23