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开发者_JS百科 .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?
It's URL rewriting through Apache: http://www.addedbytes.com/apache/url-rewriting-for-beginners/
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.
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/
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
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
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.
精彩评论