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

N00B alert: treat html as php

3 views
Skip to first unread message

Derek Turner

unread,
Nov 1, 2009, 12:04:18 PM11/1/09
to
My first post so please be gentle. I've looked for a FAQ for this group
without success so here goes!

I'm re-engineering a web-site for my choir.

I've used:

<div id="nav">
<?php include("nav.php"); ?>
</div>
<div id="top">
<?php include("top.php"); ?>
</div>

[OK I know php is overkill for SSIs, but it leaves the way open for more
fancy stuff at a later date]

so that the navigation side-bar and top-bar (which are the same on every
page) can be easily edited. So far so good, it works well.

BUT only if I give the pages the .php extension.

You can see the result here

<www.cantabilejersey.com/experimental>

I'd really prefer to use the .html extension, especially for SEO.

I've put:

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

as the only line in .htaccess

The server seems parse the .html without sending a
server-error but seems to return a .PHTML[.part] to the browser, which
seems to bork Firefox and my other browsers. Again you see this at
<www.cantabilejersey.com/experimental2>

I get the same problem if I use the SSI/shtml route, by the way.

The server is catabile1.demonweb.co.uk, if that helps.

Many tia for any help/hints you can offer to get this working.

--
Derek.

David

unread,
Nov 1, 2009, 2:45:28 PM11/1/09
to
Derek Turner wrote:
> My first post so please be gentle. I've looked for a FAQ for this group
> without success so here goes!
>
> I'm re-engineering a web-site for my choir.
>
> I've used:
>
> <div id="nav">
> <?php include("nav.php"); ?>
> </div>
> <div id="top">
> <?php include("top.php"); ?>
> </div>
>
> [OK I know php is overkill for SSIs, but it leaves the way open for more
> fancy stuff at a later date]
>
> so that the navigation side-bar and top-bar (which are the same on every
> page) can be easily edited. So far so good, it works well.
>
> BUT only if I give the pages the .php extension.
>
> You can see the result here
>
> <www.cantabilejersey.com/experimental>
>
> I'd really prefer to use the .html extension, especially for SEO.
>
> I've put:
>
> AddType application/x-httpd-php .php .html

It should be this
AddType application/x-httpd-php .htm .html

This isn't the smartest way to deal with php. What you are asking here
is for the server to parse every file with the extension .htm and .html
for any php code, process it and return the results. The problem is
that the server will look at every file (.htm & .html) wither or not it
has a bit of php code in it. The results is it shows down the server
doing this. Is that a result that you can live with? Personally the
internet is slow enough without adding any more bottlenecks to it.


>
> as the only line in .htaccess
>
> The server seems parse the .html without sending a
> server-error but seems to return a .PHTML[.part] to the browser, which
> seems to bork Firefox and my other browsers. Again you see this at
> <www.cantabilejersey.com/experimental2>

It is doing what it should be. What you are seeing is normal when the
server doesn't know how to deal with the information it is serving. It
is asking what do you want to do with it.


>
> I get the same problem if I use the SSI/shtml route, by the way.

Just how are you calling your ssi?

AddType text/html .shtml
AddHandler server-parsed .html
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes


With the above in your .htaccess you can server pages with the following
extensions .shtml or .html

Again note that serving ssi using .html extension will cause the server
to parse every file named with the .html extension wither or not there
is any ssi code in the .html file. The result is a slower server response.

Personally I would use the proper extensions instead of doing it this
half ass way. I would use a Permanent redirect from the .html file to
the new .php or .shtml file

by adding this line to your .htaccess

redirect 301 /index.html
www.cantabilejersey.com/experimental2.index.php <-- Should be on one line.

This will save your SEO ratings

--
Light Travels Faster Than Sound, Which Is Why Some People
Appear Bright Until You Hear Them Speak.

Derek Turner

unread,
Nov 2, 2009, 4:31:27 AM11/2/09
to
On Sun, 01 Nov 2009 11:45:28 -0800, David wrote:

> It should be this
> AddType application/x-httpd-php .htm .html
>
> This isn't the smartest way to deal with php. What you are asking here
> is for the server to parse every file with the extension .htm and .html
> for any php code, process it and return the results. The problem is
> that the server will look at every file (.htm & .html) wither or not it
> has a bit of php code in it. The results is it shows down the server
> doing this. Is that a result that you can live with? Personally the
> internet is slow enough without adding any more bottlenecks to it.
>
>

The point is that every page /will/ have those bits of php code inserted.
This is exactly the behaviour I want!

>
> It is doing what it should be. What you are seeing is normal when the
> server doesn't know how to deal with the information it is serving. It
> is asking what do you want to do with it.

Sorry, I did say I was a newbie. I want it serve those pages up as HTML
that a browser can recognize. How do I tell it to do that?


>
>
>
>> I get the same problem if I use the SSI/shtml route, by the way.
>
> Just how are you calling your ssi?
>
> AddType text/html .shtml
> AddHandler server-parsed .html
> AddHandler server-parsed .shtml
> Options Indexes FollowSymLinks Includes

Yes. Got that from the internet but was having the same problem. Browser
didn't recognize the output as HTML.


>
>
> With the above in your .htaccess you can server pages with the following
> extensions .shtml or .html

See above. I did all that with pseudo-comments instead of the php code.
It didn't work when I tried it. It borked the browser in exactly the same
way.

>
> Again note that serving ssi using .html extension will cause the server
> to parse every file named with the .html extension wither or not there
> is any ssi code in the .html file. The result is a slower server
> response.

See above, that's what I want as every page /will/ have the includes.


>
> Personally I would use the proper extensions instead of doing it this
> half ass way. I would use a Permanent redirect from the .html file to
> the new .php or .shtml file
>
> by adding this line to your .htaccess
>
> redirect 301 /index.html
> www.cantabilejersey.com/experimental2.index.php <-- Should be on one
> line.
>
> This will save your SEO ratings

Ah good call! Do I only have to do this for index or does it need a line
for every page? Does index.html actually have to exist on the server for
this to work (I'm guessing not, but I am a complete novice!)?

Josiah Jenkins

unread,
Nov 2, 2009, 8:36:44 AM11/2/09
to
On 2 Nov 2009 09:31:27 GMT, Derek Turner <frd...@cesmail.net> wrote:
>On Sun, 01 Nov 2009 11:45:28 -0800, David wrote:
>
<sniPPed>
From another (very recent) PHP newbie !!!
If I understand the OP correctly, I suspect there is confusion here.
(Been there, done that, got the T shirt !)

Can someone more experienced please comment ?


>>
>The point is that every page /will/ have those bits of php code inserted.

As have mine . . . header, footer and sidebar (if needed).


>
>Sorry, I did say I was a newbie. I want it serve those pages up as HTML
>that a browser can recognize. How do I tell it to do that?

I understood that's what the following (on your page) will do . . .

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-gb">


As you've discovered, if you don't have the .php extension,
any script the page, such as . . .


<?php
include("top.php");
?>

. . . will be totally ignored.


>
> Does index.html actually have to exist on the server for
>this to work (I'm guessing not, but I am a complete novice!)?

Even my index file has a .php extension.

Apologies if I've misunderstood the problem.
--


http://www.ian-stewart.eu

Derek Turner

unread,
Nov 2, 2009, 1:29:32 PM11/2/09
to
On Mon, 02 Nov 2009 13:36:44 +0000, Josiah Jenkins wrote:

>>The point is that every page /will/ have those bits of php code
>>inserted.
>
> As have mine . . . header, footer and sidebar (if needed).
>>
>>Sorry, I did say I was a newbie. I want it serve those pages up as HTML
>>that a browser can recognize. How do I tell it to do that?
>
> I understood that's what the following (on your page) will do . . .
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en-gb">

Present and correct, Sir. I suspect that something in Demon's settings,
which are above and beyond my pay-grade, is causing the problem because
every web-site I look at tells me I'm doing it right. However,
any .htaccess above what I'm allowed to alter in the fileserver hierarchy
will affect the way my files are parsed.
>
>


> Even my index file has a .php extension.

As does mine, now. However we are currently first in google's ranking on
'cantabile ensemble' and I don't want to lose that by changing the file
extension. David's suggestion of using a 301 is an excellent one and is
what I shall do, so that we don't lose the Search Engine Optimization. I
have no problem giving everything a .php on the server. The /local/
copies will have .html for testing and editing ease. A simple bash script
creates a .php for every .html in the local copy.

David

unread,
Nov 3, 2009, 12:12:17 AM11/3/09
to
As for the redirect it will need one for every file that you want to
change (redirect) from .html to .php

Also I was thinking do you have the AllowOverride options set? That
could be what is screwing you up trying to get it to parse the .html
files with the php scripts inside.

0 new messages