Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Force apache to parse html files as php

1 view
Skip to first unread message

Gary Hasler

unread,
Dec 5, 2007, 2:40:29 PM12/5/07
to
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"

Norman Peelman

unread,
Dec 5, 2007, 3:03:10 PM12/5/07
to

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

Paul Lautman

unread,
Dec 5, 2007, 3:09:20 PM12/5/07
to
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/topics

Gary Hasler

unread,
Dec 5, 2007, 3:11:09 PM12/5/07
to
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?:

<Directory />
Options Indexes FollowSymLinks
Options +Includes
AddType text/html .shtml

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

Ivan Marsh

unread,
Dec 5, 2007, 3:26:44 PM12/5/07
to
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.

Michael Fesser

unread,
Dec 5, 2007, 4:20:58 PM12/5/07
to
.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

Ivan Marsh

unread,
Dec 5, 2007, 4:37:06 PM12/5/07
to
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?

Norman Peelman

unread,
Dec 5, 2007, 5:06:28 PM12/5/07
to

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

Norm

Rik Wasmus

unread,
Dec 5, 2007, 5:26:13 PM12/5/07
to
On Wed, 05 Dec 2007 22:20:58 +0100, Michael Fesser <net...@gmx.de> 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

Lars Eighner

unread,
Dec 5, 2007, 5:55:17 PM12/5/07
to
In our last episode, <47570A79...@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 <http://larseighner.com/> use...@larseighner.com
Countdown: 411 days to go.

Gremnebulin

unread,
Dec 6, 2007, 4:12:12 AM12/6/07
to
On 5 Dec, 19:40, Gary Hasler <garyhas...@thelogconnection.com> 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.

Captain Paralytic

unread,
Dec 6, 2007, 5:41:52 AM12/6/07
to
On 5 Dec, 22:06, Norman Peelman <npeel...@cfl.rr.com> 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.

Gary Hasler

unread,
Dec 6, 2007, 6:23:54 PM12/6/07
to

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!

Gary Hasler

unread,
Dec 6, 2007, 6:28:18 PM12/6/07
to

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.

rf

unread,
Dec 6, 2007, 8:51:38 PM12/6/07
to

"Gary Hasler" <garyh...@thelogconnection.com> wrote in message
news:47588489...@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.


Norman Peelman

unread,
Dec 6, 2007, 9:48:54 PM12/6/07
to

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


---
Norm

Norman Peelman

unread,
Dec 6, 2007, 9:56:59 PM12/6/07
to


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

Gremnebulin

unread,
Dec 7, 2007, 5:59:38 AM12/7/07
to
On 6 Dec, 23:23, Gary Hasler <garyhas...@thelogconnection.com> 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.

Paul Lautman

unread,
Dec 8, 2007, 7:52:26 AM12/8/07
to

Err, the english is fine apart from the apostrophe. a file has a mime type
and so the mime type is possessed by the file, therefore the "its" indicates
that the file possesses a mime type.

If you intended it as an abbreviation, you would have been saying
"anything else should get parsed as html or it is respective mime-type."

which is utter nonesense.

Norman Peelman

unread,
Dec 8, 2007, 11:58:31 AM12/8/07
to
Paul Lautman wrote:
> Norman Peelman wrote:
>> Captain Paralytic wrote:
>>> On 5 Dec, 22:06, Norman Peelman <npeel...@cfl.rr.com> 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.
>> Exactly. I didn't use it properly, it's not meant to be possessive.
>> It's a typo.
>
> Err, the english is fine apart from the apostrophe. a file has a mime type
> and so the mime type is possessed by the file, therefore the "its" indicates
> that the file possesses a mime type.
>
> If you intended it as an abbreviation, you would have been saying
> "anything else should get parsed as html or it is respective mime-type."
>
> which is utter nonesense.
>
>
>

How many times do I have to admit I should have left the apostrophe
out. Yes, I know it was supposed to be 'its.' But hey, thanks again...

---
Norm

Paul Lautman

unread,
Dec 8, 2007, 12:10:17 PM12/8/07
to
Norman Peelman wrote:
> Paul Lautman wrote:
>> Norman Peelman wrote:
>>> Captain Paralytic wrote:
>>>> On 5 Dec, 22:06, Norman Peelman <npeel...@cfl.rr.com> 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.
>>> Exactly. I didn't use it properly, it's not meant to be
>>> possessive. It's a typo.
>>
>> Err, the english is fine apart from the apostrophe. a file has a
>> mime type and so the mime type is possessed by the file, therefore
>> the "its" indicates that the file possesses a mime type.
>>
>> If you intended it as an abbreviation, you would have been saying
>> "anything else should get parsed as html or it is respective
>> mime-type." which is utter nonesense.
>>
>>
>>
>
> How many times do I have to admit I should have left the apostrophe
> out. Yes, I know it was supposed to be 'its.' But hey, thanks
> again...
But you didn't say that you should have left the apostrophe out, you said
that it wasn't meant to be possessive.

Norman Peelman

unread,
Dec 8, 2007, 3:05:29 PM12/8/07
to

I mis-stated that comment. It was meant to be possessive but I
should have left the apostrophe out to do so. I made a mistake. My
fingers were going faster than my brain as usual.

Norm

Jerry Stuckle

unread,
Dec 8, 2007, 7:02:19 PM12/8/07
to

Normal,

Don't worry about it. Paul catches me on this rather regularly, also,
and I DO know better. :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================

John Dunlop

unread,
Dec 10, 2007, 4:28:52 AM12/10/07
to
Gary Hasler:

> 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.

Enable MultiViews and add .php to .html filenames.

--
Jock

Gary Hasler

unread,
Dec 10, 2007, 2:22:26 PM12/10/07
to
rf wrote:
>
> "Gary Hasler" <garyh...@thelogconnection.com> wrote in message
> news:47588489...@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.

Hey!...I learn sumthin' every day!

Tim Roberts

unread,
Dec 11, 2007, 1:07:33 AM12/11/07
to
Gremnebulin <peter...@yahoo.com> wrote:
>
>All you need is a linux CD. The current PC could be converted into a
>dual-boot system.

I've heard that worded slightly differently: "You need to upgrade your
Windows XP system by applying Service Pack Linux."
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

0 new messages