Forum Moderators: phranque

Message Too Old, No Replies

default index.html in other than home page

automatic showing index.html

         

jscjso

8:01 pm on Jan 20, 2010 (gmt 0)

10+ Year Member



I have Apache 2.0.63 and looked through my httpd file.
I played with directoryIndex line and still cannot get
the following work.

Here is part of my httpd:

DocumentRoot "C:/Apache Group/Apache2/htdocs"
DirectoryIndex index.html index2.html

If someone type in http://example.com, it will automatically
show the index.html on the browser. This works.

However, I have an index.html in a directory abcde
and want to automatically show the index.html in abcde
when people type http://example.com/abcde. This
does not work.

I have to have people using [mydomain.com...]
to show the index.html in abcde directory.

How do I set up my httpd file to skip the requirement
of the last slash? Most people do not know the last slash is required.

Thanks

[edited by: jdMorgan at 11:27 pm (utc) on Jan. 20, 2010]
[edit reason] Please use "example.com" [/edit]

jdMorgan

11:28 pm on Jan 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The action you describe is correct server behavior, because "/abcde" is a "page" or a "file" and not a directory.

If you wish to override this correct behavior on Apache 2.x, then refer to the Apache documentation for the DirectorySlash directive.

I would warn you that doing so violates Web standards, so this 'fix' --while it may seem expedient today-- may come back to cause problems for you in the future.

A better solution would be to 301-redirect requests with missing trailing slashes to correct the URL, instead of 'just accepting' the error and correcting it inside the server.

Jim

jscjso

6:04 pm on Jan 21, 2010 (gmt 0)

10+ Year Member



Jim,

Thanks for a quick reply.

The default DirectorySlash is On.

My understanding is that the trailing slash should be automatically added to the url without the trailing slash.

I even added DirectorySlash On and there is no difference.

The only machines that work is the servers. Any other machines needs the trailing slash to show the index.html.

Any suggestion to do it in Server side.

Jason

jdMorgan

9:13 pm on Jan 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check to make sure that mod_dir is loaded, then. mod_dir and DirectorySlash will add a trailing slash if the request does not end with a slash, the request does not resolve to an existing file, and the request does resolve to an existing directory if that slash is appended.

Jim

jscjso

4:13 pm on Jan 22, 2010 (gmt 0)

10+ Year Member



Jim,

I did check for the mod_dir. The lines are:

LoadModule access_module modules/mod_access.so
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_module modules/mod_auth.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule imap_module modules/mod_imap.so
LoadModule include_module modules/mod_include.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule ssl_module modules/mod_ssl.so

The strangest thing is the automatic trailing slash works in
the machines that have a copy of the Apache setup running. But the automatic trailing slash does not work on other machines, like client machines browsing my site.

jdMorgan

5:32 pm on Jan 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well I don't like putting band-aids on mysterious problems, but you can force the slash (at some non-negligible expense in performance) using a bit of mod_rewrite code. Assuming that you've already got other mod_rewrite rules working (and so already have the required directives to enable mod_rewrite) :

In .htaccess or inside a <Directory> container in a server config file:


RewriteCond $1 !\.[a-z0-9]$ [NC]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])$ http://www.example.com/$1/ [R=301,L]

If you need to put this code in a config file and not enclose it in a <Directory> container, then add a leading slash to the RewriteRule pattern, making it "^/(.*[^/])$".

Jim