3

I have a file

http://www.www.com/somefile.php

I would like to be able to get to the same file by going to

http://www.www.com/somefile

But I still need

http://www.www.com/directory

to open the file

http://www.www.com/directory/index.php

if, in fact, directory is a directory.

This is a typical LAMP setup with Red Hat and Apache.

Is that possible? If so, how?

Jason
  • 15,017
  • 23
  • 85
  • 116

3 Answers3

3

An apache rewrite rule will do this for you. The only limitation is you can't have a file named "somefile.php" and a directory named "somefile" (though you can still have directories.

Here's an example rule that supports multiple filenames (just put in in your .htaccess file).

RewriteEngine on
RewriteRule ^(somefile1|somefile2|somefile3) $1.php

Will change /somefile1 to /somefile1.php, /somefile2 to /somefile2.php, and /somefile3 to /somefile3.php.

SoapBox
  • 20,457
  • 3
  • 51
  • 87
2

Look at Apache's ForceType.

Eric Butera
  • 638
  • 4
  • 6
0

If you want to disable the need of file extensions on the url globally on your site, you can also add the following to your .htaccess:

Options +MultiViews

This will enable Content Negotiation. But if you want to match only certain files and/or urls, stick with SoapBox's Answer instead.

Community
  • 1
  • 1