views:

143

answers:

6

What handles the disabling of the extension? Is it APACHE or the PHP install? How would one go about configuring the web server where the .php extension is not required? Is there an option that would make both www.example.com/page.php and www.example.com/page work as the URL?

+8  A: 

It's URL rewriting through Apache: http://www.addedbytes.com/apache/url-rewriting-for-beginners/

brianreavis
+3  A: 

Check out some articles from A List Apart on this topic: You use Apache (in your case) to setup ReWriteRule's and then you have PHP parse the url to fetch the correct information. (again, in your case. You can do this with many languages and http servers)

http://www.alistapart.com/articles/succeed/

http://www.alistapart.com/articles/urls/

Bartek
+4  A: 

Apache also has a setting called MultiViews that will serve domain.com/index.* as domain.com/index, domain.com/example.* as domain.com/example, etc.

I've occasionally run into issues where MultiViews beats out mod_rewrite rules, so I tend to turn it off.

ceejayoz
+1 MultiViews should definitely be turned off if you are to use mod_rewrite, otherwise you're guaranteed a headache.
mike
+2  A: 

brianreavis is correct. Here's an example for your .htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
jeerose
+1  A: 

I just throw it all at PHP and parse it however I want in there:

.htaccess

RewriteEngine On
RewriteRule !\.(js|ico|gif|jpg|png|css)$ @frontend.php
Ben Dauphinee
+1  A: 

I use this in my .htaccess

<Files ~ "^[^.]+$">
ForceType application/x-httpd-php5
</Files>

That way I can remove all extensions (.php) from my files, and it will still work.

I use $_SERVER['PATH_INFO'] to retrieve the remainder of the path as parameters. E.g. /page/param1/param2 where page is an actual php file.

pritaeas