Forum Moderators: coopster

Message Too Old, No Replies

Using PHP in an .html file

how can I use PHP in an .html file

         

riospace

4:57 am on Oct 11, 2006 (gmt 0)

10+ Year Member



I know that you can use the following code in .htaccess to execute .html pages as PHP:

AddType application/x-httpd-php htm html

But, is there a code that can be used to accomplish running a single .html page as php instead of the above code that runs every page on the site as php?

I know that I could just change the .html to .php, but I really want to know if I can run a single .html page as php without changing the extension and without using the (AddType application/x-httpd-php htm html) code that will run all of my .html pages as php.

Tastatura

5:23 am on Oct 11, 2006 (gmt 0)

10+ Year Member



If you want just one page why not use something like this


<html>
<head>
<title>My one PHP Page</title>
</head>
<body>

<?php
your php code here
?>

</body>
</html>

is this what are you after?

riospace

9:16 am on Oct 11, 2006 (gmt 0)

10+ Year Member



>>> <html>
<head>
<title>My one PHP Page</title>
</head>
<body>

<?php
your php code here
?>
</body>
</html>

This will only work if you put a .php extension on the page. I am trying to figure out how to get the server to read this one page as php eventhough it has a .html extension without having the server read every .html page in the site as php.

Tastatura

9:25 am on Oct 11, 2006 (gmt 0)

10+ Year Member



Not sure what platform you are running but see if this helps you

Apache Module mod_mime [httpd.apache.org]

benevolent001

10:06 am on Oct 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Am not sure , may be you should ask Jim in apache forum over here

but there are some directives like

execute this if file name is this

so we can do what you want exactly if it can be used , not sure am very starter in apache

coopster

1:32 pm on Oct 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



As mentioned, if it is on an Apache HTTP Server you can specify the filename in a <Files> [httpd.apache.org] directive and put your instructions inside the container.

riospace

2:33 pm on Oct 11, 2006 (gmt 0)

10+ Year Member



I have posted this question is the Apache forum as suggested above. Thanks for all of the help.

[webmasterworld.com...]

whoisgregg

4:41 pm on Oct 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What I would recommend is to change the extension to .php of that one file then add a rewrite to your .htaccess file. (Something like the sample code below.)

RewriteRule ^example\.html$ example.php [L]