Force apache to parse html files as php

Force apache to parse html files as php

am 05.12.2007 20:40:29 von Gary Hasler

I want apache to parse all .html files for php code. Our 'real' web
server is rented from ICDsoft ( php 5 on Apache on Linux whatever), and
their instruction is to add the following to the .htaccess file:
AddHandler application/x-httpd-php .html
....which works great.

However, our local in-office server for testing and viewing our sites is
Apache 2.0.55 with PHP 4.4.4 on Windows XP Pro. I have read everything
I can find, and have tried adding the following to the httpd.conf file,
in every combination I can think of:
AddHandler application/x-httpd-php .html
and / or:
AddType application/x-httpd-php .php .html

but the page just gets sent as html without the php code being parsed at
all (and yes, I do restart Apache after each change). What am I doing
wrong?

(Here's what httpd.conf contained before--note that it works just fine
for .php files:)
ScriptAlias /php/ "c:/php/"
LoadModule php4_module "c:/php/php4apache2.dll"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php.exe"
PHPIniDir "C:/php"

Re: Force apache to parse html files as php

am 05.12.2007 21:03:10 von Norman Peelman

Gary Hasler wrote:
> I want apache to parse all .html files for php code. Our 'real' web
> server is rented from ICDsoft ( php 5 on Apache on Linux whatever), and
> their instruction is to add the following to the .htaccess file:
> AddHandler application/x-httpd-php .html
> ...which works great.
>
> However, our local in-office server for testing and viewing our sites is
> Apache 2.0.55 with PHP 4.4.4 on Windows XP Pro. I have read everything
> I can find, and have tried adding the following to the httpd.conf file,
> in every combination I can think of:
> AddHandler application/x-httpd-php .html
> and / or:
> AddType application/x-httpd-php .php .html
>
> but the page just gets sent as html without the php code being parsed at
> all (and yes, I do restart Apache after each change). What am I doing
> wrong?
>
> (Here's what httpd.conf contained before--note that it works just fine
> for .php files:)
> ScriptAlias /php/ "c:/php/"
> LoadModule php4_module "c:/php/php4apache2.dll"
> AddType application/x-httpd-php .php
> Action application/x-httpd-php "/php/php.exe"
> PHPIniDir "C:/php"

Just add .html after .php on the AddType line like so:

AddType application/x-httpd-php .php .html

and it should work. Others will tell you that that is a bad idea in that
it causes even pages that have no PHP in them to go through the PHP
parser before getting sent out to the browser. But if you have a need
for it then by all means...

I do:

..php .htm for any page that may be created by or contain PHP generated
output. You can even add your own if you want - doesn't matter. Just
don't over-ride a mime-type.

anything else should get parsed as html or it's respective mime-type. I
personally end static pages (no dynamic) with either .html or .shtml

Norm

Re: Force apache to parse html files as php

am 05.12.2007 21:09:20 von Paul Lautman

Norman Peelman wrote:
>anything else should get parsed as html or it's respective mime-type.
http://groups.google.co.uk/group/alt.possessive.its.has.no.a postrophe/topics

Re: Force apache to parse html files as php

am 05.12.2007 21:11:09 von Gary Hasler

Norman Peelman wrote:
>
> Gary Hasler wrote:
> > I want apache to parse all .html files for php code. Our 'real' web
> > server is rented from ICDsoft ( php 5 on Apache on Linux whatever), and
> > their instruction is to add the following to the .htaccess file:
> > AddHandler application/x-httpd-php .html
> > ...which works great.
> >
> > However, our local in-office server for testing and viewing our sites is
> > Apache 2.0.55 with PHP 4.4.4 on Windows XP Pro. I have read everything
> > I can find, and have tried adding the following to the httpd.conf file,
> > in every combination I can think of:
> > AddHandler application/x-httpd-php .html
> > and / or:
> > AddType application/x-httpd-php .php .html
> >
> > but the page just gets sent as html without the php code being parsed at
> > all (and yes, I do restart Apache after each change). What am I doing
> > wrong?
> >
> > (Here's what httpd.conf contained before--note that it works just fine
> > for .php files:)
> > ScriptAlias /php/ "c:/php/"
> > LoadModule php4_module "c:/php/php4apache2.dll"
> > AddType application/x-httpd-php .php
> > Action application/x-httpd-php "/php/php.exe"
> > PHPIniDir "C:/php"
>
> Just add .html after .php on the AddType line like so:
>
> AddType application/x-httpd-php .php .html
>
> and it should work. Others will tell you that that is a bad idea in that
> it causes even pages that have no PHP in them to go through the PHP
> parser before getting sent out to the browser. But if you have a need
> for it then by all means...
>
> I do:
>
> .php .htm for any page that may be created by or contain PHP generated
> output. You can even add your own if you want - doesn't matter. Just
> don't over-ride a mime-type.
>
> anything else should get parsed as html or it's respective mime-type. I
> personally end static pages (no dynamic) with either .html or .shtml
>
> Norm
Thanks Norm;
however I figured out what was happening (always happens if I post a
question!)..
I had SSI turned on earlier in the httpd.conf and I guess it can't do
both?:


Options Indexes FollowSymLinks
Options +Includes
AddType text/html .shtml

# --THESE LINES HAD TO BE DELETED:
#AddOutputFilter INCLUDES .html
#AddHandler server-parsed .html

Re: Force apache to parse html files as php

am 05.12.2007 21:26:44 von Ivan Marsh

On Wed, 05 Dec 2007 19:40:29 +0000, Gary Hasler wrote:

> I want apache to parse all .html files for php code.

May I ask why files that contain PHP code are being named .html and not
..php?

--
I told you this was going to happen.

Re: Force apache to parse html files as php

am 05.12.2007 22:20:58 von Michael Fesser

..oO(Ivan Marsh)

>On Wed, 05 Dec 2007 19:40:29 +0000, Gary Hasler wrote:
>
>> I want apache to parse all .html files for php code.
>
>May I ask why files that contain PHP code are being named .html and not
>.php?

Some things simply don't belong to a URL.

Cool URIs don't change
http://www.w3.org/Provider/Style/URI

| What to leave out
| [...]
| * File name extension. This is a very common one. "cgi", even ".html"
| is something which will change. You may not be using HTML for that
| page in 20 years time, but you might want today's links to it to
| still be valid. The canonical way of making links to the W3C site
| doesn't use the extension.
| * Software mechanisms. Look for "cgi", "exec" and other give-away
| "look what software we are using" bits in URIs. Anyone want to
| commit to using perl cgi scripts all their lives? Nope? Cut out the
| .pl. Read the server manual on how to do it.

Micha

Re: Force apache to parse html files as php

am 05.12.2007 22:37:06 von Ivan Marsh

On Wed, 05 Dec 2007 22:20:58 +0100, Michael Fesser wrote:

> .oO(Ivan Marsh)
>
>>On Wed, 05 Dec 2007 19:40:29 +0000, Gary Hasler wrote:
>>
>>> I want apache to parse all .html files for php code.
>>
>>May I ask why files that contain PHP code are being named .html and not
>>.php?
>
> Some things simply don't belong to a URL.

Who said anything about belonging in a URL? If you're stripping file
extensions what difference does it make what the file extension is?

The file extension tells the webserver how to interpret the file... so why
not name PHP scripts .php rather than .html?

--
I told you this was going to happen.

Re: Force apache to parse html files as php

am 05.12.2007 23:06:28 von Norman Peelman

Paul Lautman wrote:
> Norman Peelman wrote:
>> anything else should get parsed as html or it's respective mime-type.
> http://groups.google.co.uk/group/alt.possessive.its.has.no.a postrophe/topics
>
>
>

It does in the proper context... which I didn't use. :)

Norm

Re: Force apache to parse html files as php

am 05.12.2007 23:26:13 von luiheidsgoeroe

On Wed, 05 Dec 2007 22:20:58 +0100, Michael Fesser wrote:

> .oO(Ivan Marsh)
>
>> On Wed, 05 Dec 2007 19:40:29 +0000, Gary Hasler wrote:
>>
>>> I want apache to parse all .html files for php code.
>>
>> May I ask why files that contain PHP code are being named .html and not
>> .php?
>
> Some things simply don't belong to a URL.
>
> Cool URIs don't change
> http://www.w3.org/Provider/Style/URI

.... and URI's have little to do with where the request ends up on a sever
anyway...

Come to think of it, close to none of my recent projects use any URI
ending in an extension, save for some back-end/CMS functionality not
publically available. They are a way to advertise to search engines/make
them accessable by guessability/should reflect some sort of indication of
the actual content they'll show, so I treat them as such.
--
Rik Wasmus

Re: Force apache to parse html files as php

am 05.12.2007 23:55:17 von Lars Eighner

In our last episode, <47570A79.CAA856F0@thelogconnection.com>, the lovely
and talented Gary Hasler broadcast on comp.lang.php:

> I had SSI turned on earlier in the httpd.conf and I guess it can't do
> both?:

No, you can't. You can write out a file from php with SSI to be served
later and if things are configured properly that file can be parsed for
SSI, but you cannot serve a php file and have it parsed for SSI, nor can you
serve cgi with SSI that you mean to be parsed, include php via SSI, nor just
about any other combination you can think of.

This is a pretty reasonable limitation if you think about it --- just how
many bites at the preprocessing apple should a server allow you before it
sends the document out? Since it is trivial in php or cgi to do includes,
even includes which in other contexts may be done by SSI, this should not
pose many difficulties.

--
Lars Eighner usenet@larseighner.com
Countdown: 411 days to go.

Re: Force apache to parse html files as php

am 06.12.2007 10:12:12 von Gremnebulin

On 5 Dec, 19:40, Gary Hasler wrote:
> I want apache to parse all .html files for php code. Our 'real' web
> server is rented from ICDsoft ( php 5 on Apache on Linux whatever), and
> their instruction is to add the following to the .htaccess file:
> AddHandler application/x-httpd-php .html
> ...which works great.
>
> However, our local in-office server for testing and viewing our sites is
> Apache 2.0.55 with PHP 4.4.4 on Windows XP Pro.

At the risk of being annoying: a test system isn't much of a test if
it doesn't duplicate
the target system.

Re: Force apache to parse html files as php

am 06.12.2007 11:41:52 von Captain Paralytic

On 5 Dec, 22:06, Norman Peelman wrote:
> Paul Lautman wrote:
> > Norman Peelman wrote:
> >> anything else should get parsed as html or it's respective mime-type.
> >http://groups.google.co.uk/group/alt.possessive.its.has.no. apostrophe...
>
> It does in the proper context... which I didn't use. :)
>
> Norm

No, there is no context where a posseive its has an apostrophe.

Re: Force apache to parse html files as php

am 07.12.2007 00:23:54 von Gary Hasler

Gremnebulin wrote:
>
> On 5 Dec, 19:40, Gary Hasler wrote:
> > I want apache to parse all .html files for php code. Our 'real' web
> > server is rented from ICDsoft ( php 5 on Apache on Linux whatever), and
> > their instruction is to add the following to the .htaccess file:
> > AddHandler application/x-httpd-php .html
> > ...which works great.
> >
> > However, our local in-office server for testing and viewing our sites is
> > Apache 2.0.55 with PHP 4.4.4 on Windows XP Pro.
>
> At the risk of being annoying: a test system isn't much of a test if
> it doesn't duplicate
> the target system.

True; but I'm getting better--it used to be Microsoft IIS!
I guess I should set up Apache the way ICDsoft does, and then create
identical .htaccess files, maybe someday..
As far as the OS goes, the only quirks I've run into are:
- Windows won't let me create a file named .htaccess
- The case-sensitive filename issue
Right now I do a lot of work in Windows-only software, so it's just
easier to run the test site on windows. Some day I'll get a Linux
server and set it up JUST right!

Re: Force apache to parse html files as php

am 07.12.2007 00:28:18 von Gary Hasler

Ivan Marsh wrote:
>
> On Wed, 05 Dec 2007 22:20:58 +0100, Michael Fesser wrote:
>
> > .oO(Ivan Marsh)
> >
> >>On Wed, 05 Dec 2007 19:40:29 +0000, Gary Hasler wrote:
> >>
> >>> I want apache to parse all .html files for php code.
> >>
> >>May I ask why files that contain PHP code are being named .html and not
> >>.php?
> >
> > Some things simply don't belong to a URL.
>
> Who said anything about belonging in a URL? If you're stripping file
> extensions what difference does it make what the file extension is?
>
> The file extension tells the webserver how to interpret the file... so why
> not name PHP scripts .php rather than .html?

Because I'm switching to a PHP scripted menu / header include system,
that means I will need all 50 of our existing html pages to be processed
by PHP. And I'd rather not break our customers' existing bookmarks,
plus search engine links.

Re: Force apache to parse html files as php

am 07.12.2007 02:51:38 von rf

"Gary Hasler" wrote in message
news:47588489.62633825@thelogconnection.com...
> Gremnebulin wrote:

> - Windows won't let me create a file named .htaccess

Windows Explorer won't. The file system does not care. So, start up notepad
and save the file as ".htaccess", including the quotes. No problem.

> - The case-sensitive filename issue

I've never had a problem. Then again *all* my filenames are lower case.

--
Richard.

Re: Force apache to parse html files as php

am 07.12.2007 03:48:54 von Norman Peelman

Captain Paralytic wrote:
> On 5 Dec, 22:06, Norman Peelman wrote:
>> Paul Lautman wrote:
>>> Norman Peelman wrote:
>>>> anything else should get parsed as html or it's respective mime-type.
>>> http://groups.google.co.uk/group/alt.possessive.its.has.no.a postrophe...
>> It does in the proper context... which I didn't use. :)
>>
>> Norm
>
> No, there is no context where a posseive its has an apostrophe.

Exactly. I didn't use it properly, it's not meant to be possessive.
It's a typo.


---
Norm

Re: Force apache to parse html files as php

am 07.12.2007 03:56:59 von Norman Peelman

Gary Hasler wrote:
> I want apache to parse all .html files for php code. Our 'real' web
> server is rented from ICDsoft ( php 5 on Apache on Linux whatever), and
> their instruction is to add the following to the .htaccess file:
> AddHandler application/x-httpd-php .html
> ...which works great.
>
> However, our local in-office server for testing and viewing our sites is
> Apache 2.0.55 with PHP 4.4.4 on Windows XP Pro. I have read everything
> I can find, and have tried adding the following to the httpd.conf file,
> in every combination I can think of:
> AddHandler application/x-httpd-php .html
> and / or:
> AddType application/x-httpd-php .php .html
>
> but the page just gets sent as html without the php code being parsed at
> all (and yes, I do restart Apache after each change). What am I doing
> wrong?
>
> (Here's what httpd.conf contained before--note that it works just fine
> for .php files:)
> ScriptAlias /php/ "c:/php/"
> LoadModule php4_module "c:/php/php4apache2.dll"
> AddType application/x-httpd-php .php
> Action application/x-httpd-php "/php/php.exe"
> PHPIniDir "C:/php"


Also take a look at the 'AccessFileName' directive. It's a directive
that allows you to change the name of .htaccess files if you so desire.

---
Norm

Re: Force apache to parse html files as php

am 07.12.2007 11:59:38 von Gremnebulin

On 6 Dec, 23:23, Gary Hasler wrote:

> True; but I'm getting better--it used to be Microsoft IIS!
> I guess I should set up Apache the way ICDsoft does, and then create
> identical .htaccess files, maybe someday..
> As far as the OS goes, the only quirks I've run into are:
> - Windows won't let me create a file named .htaccess
> - The case-sensitive filename issue
> Right now I do a lot of work in Windows-only software, so it's just
> easier to run the test site on windows. Some day I'll get a Linux
> server and set it up JUST right!


All you need is a linux CD. The current PC could be converted into a
dual-boot system.