Mod Rewrite Remove .php

Hi,

I am trying to remove the .php from the end of file names on my site. I have tried around 15 variations and contacted the host but I still cant get it to work. The thing I am puzzled about is that their are so many different options.

DOes anyone know sure fire way to remove the .php please?

A semi-helpful piece of information is that when I copy-pasted your htaccess, it worked just fine on my local server.

But for what it’s worth, before I tried it, I expected this line to fail:

RewriteCond %{REQUEST_FILENAME}.php -f

The reason I expected this line to fail is because you’re using URLs with trailing slashes, so I expected this test to evaluate like so:

RewriteCond /www/index/.php -f

See how the trailing slash might cause a problem? But I have to emphasize again that this is the behavior I expected, not the behavior I saw. Apache turned out to be smart enough to discard the trailing slash (or at least the 2.4 version of Apache was).

EDIT: Also, make sure you have this line at the beginning.

RewriteEngine On

Thanks,

But I dont really understand this. Is their a standard method of removing .php?

There is, and you’re doing it. Like I said, your htaccess code works fine on my local server.

Just to make sure you’re aware: As written, your non-php URLs need a trailing slash.

Thanks,

But I still understand. I’ve tried so many different options I’m confused. If I try the following code what stops it from working with my site please?

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php -f

Those aren’t the only two lines in your htaccess, are they…?

Yes. I have tried lots of different options. Some 2 pages long.

Well, the two lines you just posted won’t work by themselves, because there aren’t even any rewrite rules in there. But the htaccess you linked to in your first post seems to work just fine on my local server, except that I added the RewriteEngine On line.

Thanks,

You mean this one. The one produced by blog?


RewriteRule ^about$ about.php [L]

Could you please detail the code that should be used? I would be very grateful.

Hi,

Does anyone have any suggestions please on how I can fix this. It appears simple but what ever I try doesn’t seem to work.