Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Extensionless Files

Different Methods, Same Result



10:22 pm on Mar 3, 2007 (gmt 0)

5+ Year Member


I've been reading a lot about extensionless URLs and the different ways to accomplish them.

I want to use the following method with php:

  • I save php files without any extension on my server (e.g. "foo", not "foo.php").

  • I add "DefaultType application/x-httpd-php" to my .htaccess to make apache treat extensionless files like php-files.

  • I also add the following code to my .htaccess to remove trailing slashes from URLs if they refer to extensionless files (but not directories):

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

Since I'm not much of an expert I'd like to ask if there's anything wrong with my approach. I have read jdMorgan's post [webmasterworld.com] that says:

The right way to do this is name the files as .php, and then rewrite the URLs that have no extension to those filenames using mod_rewrite.

I figured that my way would be slightly faster than a method including mod_rewrite. Am I missing anything here? Could I run into some unforseen trouble with this method?



2:10 am on Mar 4, 2007 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

If it works, it works...

Test it to be sure.



3:09 pm on Mar 4, 2007 (gmt 0)

10+ Year Member

I'd be careful using DefaultType because in addition to extensionless files, it will also apply that content-type to extensions that are not specified in mime.types or via httpd.conf directives -- this could crash or at least slow your HTTPd by allowing PHP to attempt to parse/run files it has no way of handling.

Apache can run PHP files without extension wherever scripts/CGI can run as long as their first line is a declaration to the executable that loads them:

In Windows: #!C:/apps/php/php-4.3.11-Win32/php.exe -q

In *NIX: #!/usr/local/bin/php5/bin/php


Featured Threads

Hot Threads This Week

Hot Threads This Month