homepage Welcome to WebmasterWorld Guest from 54.205.59.78
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Visit PubCon.com
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
polarbear




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

Howdy,

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?

Thanks!
-Harry

 

jdMorgan




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

If it works, it works...

Test it to be sure.

Jim

spinnercee




msg:3270677
 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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved