Forum Moderators: phranque

Message Too Old, No Replies

Serving extensionless files as PHP

         

joshuakaufman

10:09 pm on Dec 19, 2004 (gmt 0)

10+ Year Member



I would like to serve both index and non-index files as PHP. For example, I have files named /index and /article_title

I'm currently using the following in my .htaccess to serve these files as HTML.


DefaultType text/html
DirectoryIndex index index.html

Any ideas on how I can also serve them as PHP without adding a PHP extension? Ideally, I would like to have the option of serving them as HTML or PHP.

Thanks for your help!

jetboy_70

10:31 pm on Dec 19, 2004 (gmt 0)

10+ Year Member



I *think* the regex is right for matching extensionless files:

<FilesMatch "^[^\.]+$">
ForceType application/x-httpd-php
</FilesMatch>

Chuck that in your Apache config or in a .htaccess file in any directory where you want extensionless files to be parsed as PHP.

joshuakaufman

8:30 am on Dec 20, 2004 (gmt 0)

10+ Year Member



Thanks jetboy. While I was waiting for a response, I tried simply changing the DefaultType, which seems to work. Here's what I'm using now:


DefaultType application/x-httpd-php
DirectoryIndex index index.html

If this serves all files as PHP by default, why would a regex be needed?