Normally php scripts are not the only thing that is served by your web server. So when your trying to solve one problem you need to make sure you don’t cause more problems in the process.
So to answer just the question asked you can try something along these lines:
AliasMatch ^(.*) $1.php
This will grab all urls and add .php to the end. And of course it will cause you countless problems with graphics, style sheets, or any static html. But if php scripts is all that you serve you got it made.
Vinnie’s got what looks like a pretty good solution but you can also do that with mod_rewrite (on an Apache server – the setup should just take removal of the default comment - # - at the beginning of the Load Module mod_rewrite … line within httpd.conf) with the following in your root level .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_URI} !\\.php$
RewriteRule ^(.*)[color=red]+[/color]$ $1.php [L]
The RewriteCond(ition) is required to eliminate the loop which would add endless .php extensions and will rewrite EVERYTHING with a .php extension.
Since this WILL cause problems if you address a directory (including root) like this, I’ve added the + to require SOMETHING in the {REQUEST_URI} string 'cause a redirect to example.com/.php won’t make any sense – you’ll have to be sure that you don’t do that with subdirectories.
Content negotiation already works. I already removed the file extensions from the links and it works. But, links from other sites still have the php extension and Opera for some reason reloads the document adding the file extension when you click on a fragment link (e.g. #menu).
To handle the INCOMING links to get rid of the .php (so content negotiation can replace it), we can change what I’d given you before with:
RewriteEngine On
RewriteRule ^(.*)+\\.php$ $1 [R=301,L]
That will redirect all requests for .php scripts to the same request without the .php extension AND show the new URL in the location box (sans “.php”). It leaves it to Content Negotiation to process the filename request as a php script.
NOTE: This should also leave your image links alone as they’d NOT have the .php extension.
Aw, I need to have a little fun with all these aliases :agree:
Anyway, there MUST be something else in your .htaccess which redirects 'cause
RewriteEngine On
RewriteRule ^(.*)+\\.php$ $1 [R=301,L]
uses the dreaded EVERYTHING atom followed by .php to redirect to EVERYTHING without the .php.
Hmmm, maybe you should omit the + as it merely requires one or more instances of the EVERYTHING atom. If that’s the cause of your problem, please accept my apologies for leaving that in from my first post (which was meant to eliminate the “directory only” request at root).