homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Extensionless Files
Different Methods, Same Result

5+ Year Member

Msg#: 3270262 posted 10:22 pm on Mar 3, 2007 (gmt 0)


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?




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

Msg#: 3270262 posted 2:10 am on Mar 4, 2007 (gmt 0)

If it works, it works...

Test it to be sure.



10+ Year Member

Msg#: 3270262 posted 3:09 pm on Mar 4, 2007 (gmt 0)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved