How to run PHP scripts with a different file extension

Sometimes you might want to execute PHP using a non-PHP file extension, for instance you might have an image handling script which you would like to be called imageHander.jpg instead of imageHandler.php.

To accomplish this, create a file called .htaccess in the same directory as the script. The filename must be exact and most text editors will allow you to save a file with this filename. If you already have a .htaccess file, you can edit it. Either way, add the line:

Code:

AddType application/x-httpd-php5 .jpg

This will allow .jpg files in that directory to execute as PHP.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to make .htm and .html files execute as PHP

To execute a .htm or .html file as if it were a PHP script, you just need to add the following...

An Introduction to Custom PHP.ini

With so many Content Management Systems available, and each having it's own particulars,...

PHP in Cron

In a cron job, when you want to execute a PHP script, you would often use the php command. On the...