Forum Moderators: phranque
I'm running Apache 1.3.29 and in my httpd.conf, the entry for the DirectoryIndex is as follows:
<IfModule mod_dir.c>
DirectoryIndex mysite.html index.html
</IfModule>
mysite.html is the homepage for my website and index.html is a page where I use javascript to redirect users to mysite.html. I'm using a content management system to manage the website and Apache deployed as a front-end web server to service users request. Whenever the homepage is updated (via the CMS), mysite.html gets replaced with the new version. There are good reasons why mysite.html is used instead of index.html, but I think it's quite irrelevent to describe here.
My problem is, for some peculiar reason, at times, whenever the homepage gets updated, mysite.html on the Apache got removed (instead of replaced) by the CMS. However, i discovered that with index.html (which contains the javascript redirect to mysite.html), the CMS succeeds in publishing the new mysite.html to the Apache server.
So it seems sensible to me to place index.html after mysite.html in the DirectoryIndex, such that, the default is mysite.html, but in the event that mysite.html is missing, index.html is used instead.
However, Apache's behaviour in not what I had expected.
1. Using the CMS, I update the homepage.
2. I access the website (www.mysite.com) and is redirected to www.mysite.com/mysite.html. This is right as after updating the homepage (mysite.html), the copy on Apache is removed. So, index.html is used instead and index.html redirects users to mysite.html. This causes the CMS to successfully publish mysite.html. So www.mysite.com/mysite.html gets me the homepage.
3. I close the browser and access www.mysite.com. I expect not to be redirected as mysite.html already exists, but I still get redirected.
4. After a while, well about 30 mins or so, I do not get redirected, ie, request to www.mysite.com is no longer redirected to www.mysite.com/mysite.html. It simply uses mysite.html as the index page.
I know that there's probably some bug in the CMS and have already contacted the vendor. But even so, APache's behaviour does seem a little unexpected to me.
I would really appreciate any thoughts in this to enable me to better understand the DirectoryIndex
Thank you in advance.
sharudin
Weclome to WebmasterWorld!
DirectoryIndex works as you described it; It defines the "index file" or default page to be served when "/" is requested. If the first file does not exist, the second one is served, and so on.
Before we get into discussion of obscure errors, let's take a clue from your "doesn't work right away, works later" and "closed my browser and then re-opened it" statements. I suspect you're dealing with a simple caching issue here, combined with the (non-optimal) use of JavaScript to do a redirect.
A simple test would be to flush your browser cache (Temporary Internet Files in IE) after your index.html JS redirect page has been loaded. Then, test to see if a request for "/" correctly returns mysite.html.
If so, I suggest the following:
1) Remove the JS redirect from index.html.
2) Change the CMS to do the following during an update:
In this way, a copy of the 'old' mysite.html content remains available as index.html while the CMS updates the mysite.html file, and no redirect is needed.
Closing the browser and re-opening it does not clear the local cache. As such, it contains a copy of the pages that were fetched from your serve before the update. This will be true for your users as well -- Each user will have a copy of the old pages in their browser cache until the specified page expiry time is reached, until the browser's default page expiration time is reached, or until the page is replaced in favor of more-recently-visited pages.
As a longer-term project, use a tool such as the server headers checker [webmasterworld.com] in the WebmasterWorld control panel to investigate the cache-control headers output by your server. See Apache mod_expires and mod_headers. A review of your site's caching policies seems to be needed.
After adding or correcting the cache-control headers served with your pages, step three of the procedure above will no longer be necessary.
Jim
Thanks for your advice. Yes, I finally manage to overcome the problem. This is what I did.
1. I did a test by clearing the browser cache as you suggested and you are right, it did bring my to mysite.html.
2. I've inserted these tags in the index.html and apec.html
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
3. I've also append the server header with
Cache-Control "public, must-revalidate"
It's working perfectly now. Million thanks Jim.
I've also been looking at other issues and learning lots about Apache. This forum is really helpful, Jim.
sharudin