Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I noticed apache2 will load a page, let's say info.php, even if the url is specified without a file extension like mysite.com/info

I thought you would need to do a mod_rewrite of some form to get that functionality but apparently it's the default functionality in my system.

Is there any way to prevent this default behavior so only pages with file extensions can be specified?

I have rewrite disabled fyi.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

What you are running into is a piece of one of the core modules of apache: mod_dir.

The directive you want to look for is DirectoryIndex this tells apache to look for certain file names when there is no absolute filename specified. The default is generally a line that looks like:

DirectoryIndex index.html index.php default.html default.php default.pl

If you don't want to have it search for these files, and display them by default you need to find the DirectoryIndex line in you apache config file and either comment it out or get rid of everything after the DirectoryIndex statement.

share|improve this answer
    
Thanks, you're handle reminds me of zephyr song lol –  user784637 Mar 5 '12 at 23:01
    
I'm pretty sure this is wrong. mod_dir only handles the typical files, like index.* and default.*. Note that he described "info.*" which would be really bizarre to find as a value for DirectoryIndex. –  Insyte Mar 6 '12 at 8:54
add comment

The magic you're seeing is performed by the MultiViews option of mod_negotiation.

From the Apache docs:

If the server receives a request for /some/dir/foo and /some/dir/foo does not exist, then the server reads the directory looking for all files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements, and returns that document.

Disable this magic by turning off MultiViews either in the apache config or in a .htaccess file:

Options -MultiViews
share|improve this answer
    
+1; MultiViews seems more likely than DirectoryIndex in this case. –  nickgrim Mar 6 '12 at 9:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.