Created September 4, 2001

How to make .php files masquerade as .php3

On's thelist it was asked by muinar:

I switched to a new server which has php4 installed instead of the old php3. I renamed all the pages and links to .php (The old version needed the filename ending php3)

Now when a visitor uses an old bookmark which ends with .php3, he will get a 404 error. Is there a way to rewrite or redirect users to the according php page? If this can be done with mod_rewrite in Apache, I'd appreciate any hints.

And the Answer:

How about this - put this in an .htaccess file at your root level directory.

RewriteEngine On
RewriteRule  ^(.+).php3 $1.php

Now, everytime Apache sees php3, it will make believe that it's really php. This will also propagate to child directories.

It's a very simple solution, though I'm not sure it's the best solution performance-wise. Also, playing with mod_rewrite is always a bit scary, make sure you leave yourself an undo and test it. You can easily make things which break spectacularly.

blog comments powered by Disqus