Efficently specify default listings for each directory

  • Enselic
  • Newbie
  • Newbie
  • User avatar
  • Posts: 6

Post 3+ Months Ago

Hi, I'm new to this board, since I'm new to Apache + PHP + MySQL.

I'd like to specify a default file that the server sends when you visit each directory. I tried to search for answers, but it is hard to form a question.

I.e if you'd visit http://www.chromecode.com/about I'd like the server to view about.php. It is just ugly to have like 6 index.php files, one in each subdirectory.

As far as I know, this could be solved by adding about.php, downloads.php, etc to the DirectoryIndex directive in Apache's config file. I could also have a .htacces in each directory that specified what file to send as the listing-file.

These methods seems very irrational to me though, is there any efficent way to specify "default files" for each directory?

I apologize if I'm beeing noobish.
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

in your Apache's httpd.conf file, look for the line that says something like:
DirectoryIndex index.html

and change DirectoryIndex to whatever you want, you can specify multiple names separated by spaces also, like:
DirectoryIndex index.shtml index.html

which will look for index.shtml and, if it doesn't exist, look for index.html instead. This still requires however that an index.shtml or index.html file actually exists within whatever directory. If you're trying to serve the exact same page, no matter which directory, you can always do

AliasMatch ^/([^/]*)/?(.*) /mystuff/$1/$2

In this example, if a user enters the URL
http://www.mysite.com/directory/file.html
Apache will serve the page located at /mystuff/directory/file.html

Or, to get the exact same page:

AliasMatch ^/([^/]*)/?(.*) /htdocs/served/$2

will serve the file located at /htdocs/served/file.html if the URL is
http://www.mysite.com/directory/file.html, or
http://www.mysite.com/files/file.html or
http://www.mysite.com/mystuff/file.html.


AliasMatch also goes into the httpd.conf file.

hth
This
  • Enselic
  • Newbie
  • Newbie
  • User avatar
  • Posts: 6

Post 3+ Months Ago

So you mean that the best way to solve this is to have:

DirectoryIndex index.php about.php downloads.php links.php etc

How about if your server hosts several sites and each of them had 5 pages, if you hosted 5 sites, that would mean 25 entries in DirectoryIndex. Do servers do this?
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

Why not just have
DirectoryIndex index.php
and call them as
http://www.mysite.com/downloads/
http://www.mysites.com/about/
and so on and so forth, with an index.php in each directory?

otherwise, if you're trying to create a file structure like
downloads/downloads.php
about/about.php
then yes, you'll have to tell the server to look for each one in the order you want it to look - though this seems somewhat redundant.
Another way (which I think you've tried already) would be to put a DirectoryIndex statement into each directory's .htaccess file.

I guess maybe I'm not clear on just what you're trying to do here if the previous didn't help you any. Are you trying to serve the same file no matter which directory you call, or are you trying to serve the same filename inside each directory you call?
  • Enselic
  • Newbie
  • Newbie
  • User avatar
  • Posts: 6

Post 3+ Months Ago

Is it common to have an index in each subdirectory? I mean, is it an accepted way? One reason I want this is that if I'd like to link to the downloads section I'd just write "visit: http://www.chromecode.com/downloads".

On my current site all sections are just put in an iframe on the index page, so I can't link someone to the downloads-page directly. My current site is http://www.chromecode.com (its just plain HTML) if you'd like to see what I mean.
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

It is the accepted fashion to have an index file in each directory, that is - unless the directory isn't one that gets served (like an images/ directory). Essentially, the reason for the "index" file is to tell a browser what to display instead of the index of the directory (which is why it's called index.***) you're browsing to - which is why you'll see a folder view in any open directory that doesn't have a valid index file (of whatever name you choose)

Judging from the response I get when trying the download link in your last post, you need to create an AliasMatch entry
AliasMatch ^/([^/]*)/?(.*) /~u36309259/chromecode/$1/$2
and put the full path to wherever ~u36309259/ is on your server, ie:
AliasMatch ^/([^/]*)/?(.*) /home/users/~u36309259/chromecode/$1/$2

Hope this makes sense

note to the Mods: This should probably be moved to the Website Hosting Forum

This
  • Enselic
  • Newbie
  • Newbie
  • User avatar
  • Posts: 6

Post 3+ Months Ago

I am trying to make a site that works like this guys site:
http://www.bitbliss.com

If you click on 'Links' and view the source, the file is named links, i.e. not index. And the link-url is just a url to the directory. Does he have a .htacces in each directory? I guess I could mail him and ask, but his technique can't be a new one so I guess someone here knows.
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

His filename isn't "links.htm" IE just does that when you save as or view source.

The real filename is probable /links/index.html or something like that. You don't need to specify the filename if it's listed as an index document. You can make up any name you want, but it's standard practice to name them "index" or "default"

.c


*EDIT:
Example: go to http://www.careusa.org/
Scroll to the bottom and find the link "care in the news archive"
Looking at that URL, you'll see it's "/newsroom/careinthenews/"
If you save target as, or view source, the filename comes up as careinthenews.htm, but I can tell you for a fact, the file name is index.asp (I created the file)
  • Enselic
  • Newbie
  • Newbie
  • User avatar
  • Posts: 6

Post 3+ Months Ago

I mailed him and asked, and you were right. He had index.php in each directory.

Thanks to all of you who replied.

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 96 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.