Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 5 of 5

Thread: Default Index

  1. #1

    Default Index

    Is it possible to have "open directories" (directories containing no index file) display a generic index.html/index.php/etc. by default? I'm working on a script now that will display all the contents of the local directory in a customized style and maybe offer a little extra functionality. I'm frequently adding folders to my webspace, and it would be convenient if anytime an "open directory" was encountered, it pointed to some generic index file stored elsewhere. This would eliminate the need for me to make a copy of this generic index.php every time I create a new directory.

  2. #2
    in your .htaccess you can do

    Code:
    Options +Indexes
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  3. #3
    Thanks for the response, Simplistik.

    I did some research, though, and from what I could find out about "Options +Indexes", it seems that it only enables or disables the browsing of open directories by the traditional means.

    What I'm actually looking for is for any open directory to be automatically substituted with another index file. For example, say my folders/files are setup like this, with root representing the directory of www.mydomain.com:

    --root
    ----index.html
    ----photography
    ------pic1.jpg
    ------pic2.jpg
    ------pic3.jpg
    ----defaults
    ----genericindex.php

    The way it's currently setup, if you navigate to the root directory via web browser, you'll see index.html, pretty standard, and I'd like to keep it this way - there's an index available, so use it. If, however, you go to www.mydomain.com/photography (where there is no index, you would either see the traditionally formatted open directory, listing the files (pic1.jpg, pic2.jpg, pic3.jpg) or if such browsing is disabled, I guess you would see nothing at all. What I'm trying to do is have the server say, "Oh, there's no index here in www.mydomain.com/photography/! I better resort to the default!", and then display defaults/genericindex.php.

    Hopefully I was coherent with all that. Do you think anything like this is possible?

  4. #4
    Well, I've discovered this little bit of code:

    Code:
    DirectoryIndex index.html index.php index.txt /genericindex/index.php
    Now, if neither index.html, index.php nor index.txt exist in the local directory, genericindex/index.php is displayed. The only problem is that while the url in the address bar remains the same (it doesn't change to /genericindex/index.php), the script still pulls the contents of the /genericindex/ directory rather than the directory that was intended to be viewed.

  5. #5
    Got it!
    $_SERVER['REQUEST_URI'] was the key.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012