Forum Moderators: phranque

Message Too Old, No Replies

Forcing Php in html files

         

Lorel

3:45 pm on Apr 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've been trying to get php software to work (adding comments to html pages) and being reluctant to change file names from html to php they are now telling me I can add the following link to htaccess and it will force php to work in html files.

I just want to check to make sure this won't affect ranking or make other changes I'm not aware of.

AddHandler application/x-httpd-php5 .html .php

topr8

4:43 pm on Apr 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



it won't have any unexpected consiquences.

that change would purely make apache parse all .html files through the php parser

you might want to make it

AddHandler application/x-httpd-php5 .html .htm .php

g1smd

8:37 pm on Apr 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, there is no need to change the URLs when you add PHP functionality to a site.

There are two ways to do this.

Either force .html files to be parsed for PHP content, or change the files from .html to .php and implement an internal rewrite so that when a .html URL is requested the server looks for the matching .php file to carry out the request.

To be clear, URLs and files are not at all the same thing, and the action of a server is to map a URL request to an internal file.

Lorel

1:17 am on Apr 6, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for the info!

Lorel

4:26 pm on Apr 13, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I had a problem with the line in the htaccess file mentioned above. I read several other websites with people having the same problem and haven't seen a solution yet.

This server is an Apache using Php5 and the host said php was working. It is also set up to use PHP as apache module:

AddHandler application/x-httpd-php5 .html .php

It causes the includes to not work and also wants to download the page.

I tried to use "AddType" instead and also took out the "5" on php with the same result (the includes work with the AddHandler so it should work for this too-- yes?)

I then tried another comment script and that one recommended this slightly different line of code:

AddType application/x-httpd-php .html

This one allowed the includes to work but it still wanted to download the page.

BTW, I haven't added the php code to the page yet. Is that needed before the above will work?

Here is the htaccess file:

-------------
AddHandler server-parsed .html
AddHandler application/x-httpd-php5 .html .php

Options +FollowSymLinks +Includes
RewriteEngine on
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
-----------

can someone tell me what might be causing the includes to not work with the first line of code and the page to want to download with both of them?

g1smd

7:49 pm on Apr 13, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This stuff is always tricky and I find the exact solution varies between hosting companies.

Not sure that you actually need this line:
AddHandler server-parsed .html

Lorel

11:22 pm on Apr 13, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not sure that you actually need this line:
AddHandler server-parsed .html


that is what loads my includes.

g1smd

7:51 am on Apr 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What sort of includes are they?

I'm not so sure you can use SSI and PHP at the same time.

topr8

9:17 am on Apr 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i'm not an apache expert but do

AddHandler server-parsed .html
AddHandler application/x-httpd-php5 .html .php

conflict with each other?

if you want to use includes and parse as php why don't you just use php includes?

Lorel

2:17 pm on Apr 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I haven't tried using PHP includes instead of SSI because I don't know PHP. Would that be easy to set up or would it involve a bit learning curve?

topr8

4:31 pm on Apr 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>>I haven't tried using PHP includes instead of SSI because I don't know PHP

ok, i don't want to sound rude here, but if you don't know any php, going back to your original post why do you want to parse .html files as php - how are you expecting to do anything without knowing any php?

as it happens php includes are very simple
here is the official manual:

[php.net...]

Lorel

7:05 pm on Apr 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



ok, i don't want to sound rude here, but if you don't know any php, going back to your original post why do you want to parse .html files as php - how are you expecting to do anything without knowing any php?


Because the site that produced the Comment software said it was "simple" to set up their code on html pages. Maybe for a programmer - which I'm not.

It appears that comment code is only written in php so I'm trying to figure out how to make it work. I don't have time to learn a new scripting language however.

g1smd

8:03 pm on Apr 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, PHP includes are very simple, and PHP itself isn't particularly difficult.

I haven't used SSI for more than a decade, just do it all in PHP these days.