I'm programming for an Apache server and I need for just one specific html page (say, first.htm) to be processed as PHP script. Is it possible to set up?
Asked
Active
Viewed 1,176 times
3 Answers
4
SetHandler
directive can be used, too:
Forces all matching files to be processed by a handler
When placed into an .htaccess file or a or section, this directive forces all matching files to be parsed through the handler given by handler-name.
<Files first.htm>
SetHandler application/x-httpd-php
</Files>

Salman A
- 262,204
- 82
- 430
- 521
-
3+1 - This is actually the proper way to do it. AddType is for MIME types, which are a totally different concept and it was a mistake for PHP to recommend configuring it that way. The PHP docs no longer recommend using AddType and now recommend SetHandler. – Dondi Michael Stroma Jun 28 '12 at 01:54
3
Create a file called .htaccess
and place it in the directory this file will be in. Add this line to ti:
<Files first.htm>
AddType application/x-httpd-php .htm
</Files>

John Conde
- 217,595
- 99
- 455
- 496
-
Yes, that will do it with all HTML page. I need it for just one specific page. – ahmd0 Jun 27 '12 at 20:04
-
Thanks. Can I specify a path to the .html file as well to remove possible ambiguity? – ahmd0 Jun 27 '12 at 20:07
-
1Not necessary if you put the htaccess file in the same directory as the file. – John Conde Jun 27 '12 at 20:09
-
-
-
If I may further the question: any way to set it so that all `.htm` can be set instead of a single file? – Funk Forty Niner Jun 27 '12 at 20:32
-
Just use `AddType application/x-httpd-php .htm` only. Ignore the tags. – John Conde Jun 27 '12 at 20:33
2
<Files first.htm>
ForceType application/x-httpd-php
</Files>

Puggan Se
- 5,738
- 2
- 22
- 48
-
Interesting. What is the difference between AddType as suggested above and ForceType? – ahmd0 Jun 27 '12 at 20:09
-
1AddType have a 2nd parameter, in johns case ".htm", ForceType chane type on all files in the current scope, while AddType change the type on all files in the scope that ends whit .htm – Puggan Se Jun 27 '12 at 20:11