PDA

View Full Version : Converting HTML Templates to include PHP


flamesong
07-18-2009, 01:34 PM
Hi,

This is my first post - I arrived here via Google believing that I might have found an answer to my question - however, having got here I don't seem to be able to find it.

Basically, I have a website of 200+ pages which I created about five years ago. I use an HTML template because that was all I knew about at the time. I have now discovered the benefits of PHP but it's too late to start my site all over again.

Is there a way that I can convert the template to allow PHP includes and still retain the .html extension - so that external incoming links won't be broken, i.e. links on other sites linking to mine?

I have found a few tutorials which give basic information but when I tried to apply this using PHP tags, when I preview my template the 'include' data is not displayed.

Grateful for any advice.

coloeagle
07-18-2009, 03:10 PM
What type of server is your site hosted on. If it is an apache server you could add a rule to your htaccess file to have the html pages treated as php.

flamesong
07-18-2009, 03:19 PM
Hi,

Thanks for the reply. That would have been an answer to part of the problem.

As often happens, since posting only an hour ago, I have found another way of doing what I wanted to do. I think being in a rut, as far as using templates goes, I was blind to some of Dreamweaver's features and at first tried using Library items but that was a waste of time as it basically still meant that my whole site needed updating whenever i made a change to a template.

But then I found Server Side Includes which is pretty much does what I need.

coloeagle
07-18-2009, 03:22 PM
Glad you got it sorted.

Just so you will have it or for others looking for this.

In your .htaccess file add the following line;
AddType application/x-httpd-php .php .htmlThis will have all html pages treated as php giving you the benefit to use the power of php for your website.

No need to change the page extensions.

flamesong
07-18-2009, 03:57 PM
Actually, I thought it was sorted - everything worked OK locally but when I uploaded my site it didn't work. Evidently, my server does not support Server-Side Includes.

I guess that is the end of my project to streamline my website.

flamesong
07-18-2009, 04:30 PM
I just tried adding the line to my .htaccess file and I got the following error until I removed it:

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

DWcourse
07-18-2009, 05:45 PM
If your server uses cPanel there is an option there (Apache Handlers under the Advanced grouping) to set Apache to process php in .html files.

flamesong
07-18-2009, 05:50 PM
Unfortunately, it uses Plesk 8.4.0

domedia
07-19-2009, 06:27 PM
Just add the line to your .htaccess file.
The error you got appears if you don't do it right.

If this is still an issue just contact your host and they will help you out. My guess is that Plesk has an option for this as well.

flamesong
07-19-2009, 08:10 PM
Just add the line to your .htaccess file.
The error you got appears if you don't do it right...
I copied and pasted it directly from coloeagle's post.

It already had my 404 error redirect in it so I pasted it on the line after that and got the error.

I tried it before the 404 redirect and still got the error but my 404 redirect stopped working too.

I don't hold any hope with the webhost, I discovered that they have all the bells and whistles switched off and won't enable them about a year into a five year hosting package (though it was extremely cheap). It says in my CP that SSI is disabled and I though I have e-mailed them about it, I suspect that that is the way it will stay.

flamesong
07-21-2009, 12:56 PM
I just had this response from my webhost:

Hello,

Our server does not provide support for server side includes of any type.

If you wish to use files in such a way, you must do so using PHP scripting.

Should you have any questions or concerns, please feel free to contact us.

Bearing in mind my initial question, has anybody got any suggestions, please?

domedia
07-21-2009, 04:53 PM
Hello,

Our server does not provide support for server side includes of any type.

Just fire them. They don't have what you want.

flamesong
07-21-2009, 06:57 PM
Just fire them. They don't have what you want.
(I am) about a year into a five year hosting package (though it was extremely cheap). It says in my CP that SSI is disabled and I though I have e-mailed them about it, I suspect that that is the way it will stay.
:mad: :mad: :mad:

DWcourse
07-21-2009, 07:10 PM
Generally, I won't sign up for hosting for more than 3 months at a time. that makes it easy to walk away.

domedia
07-21-2009, 07:23 PM
If you don't want to walk away from the hosting company, then that's your choice I guess..

But why on earth would you stay? Isn't the main goal to make your sites work for you and your visitors?

flamesong
07-22-2009, 06:34 PM
But why on earth would you stay?
I can't afford to move at the moment.

Looks like I am stuck uploading the whole site every time I make changes to the template.

flamesong
08-20-2009, 12:11 AM
In your .htaccess file add the following line;
AddType application/x-httpd-php .php .htmlThis will have all html pages treated as php giving you the benefit to use the power of php for your website.

No need to change the page extensions.
I have now moved to a webhost which supports SSIs and have partially solved my problems but when I add this line to my .htaccess file, something strange happens. Rather than get an error, the page is downloaded as a PC application - I'm on a Mac and the file has a Virtual PC icon.

Any clues?

flamesong
08-20-2009, 12:40 AM
I found that by using this line instead it will parse .php:

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

However, as I mentioned, my problems are only partially solved but the problem is with SSIs in html - for some reason only the front page is parsing the SSIs - all other pages are displaying the following where the includes should be displayed:

[an error occurred while processing this directive]

When I look at the source code of the file on the server with my browser, it shows the same (above) text where the local file has the include command.

So, now I have a fully functioning front page and 300 pages with error messages all over them.

coloeagle
08-20-2009, 02:32 AM
Is the front page using an html extension or php extension?

Is the file path correct in the includes rule?

Can we have a url or the code?

flamesong
08-20-2009, 09:48 AM
The front page is html.

As far as I can be sure, the file path is correct - it works locally and was generated by a Dreamweaver template. The webhost suggested that the file path was wrong but I have tried using their suggested path, the root of which goes back to the server (not the site) home directory. That didn't work. I have also tried using absolute URLs - but that didn't help.

The main site URL is: http://www.flamesong.com

The page on which I am testing the SSIs is: http://www.flamesong.com/news/archive/index.html

If you look at the source code of the page from a browser, it will have replaced the include command with [an error occurred while processing this directive].

There are three (experimental) includes commands:

The original, generated by Dreamweaver (centre top):

<!--#include file="../../includes/googletop.html" -->

The webhost's suggested path (top right):

<!--#include file="/home/flameso1/public_html/includes/cafepressshirts.html" -->

With an absolute URL (top left):

<!--#include file="http://www.flamesong.com/includes/fslogo.html" -->

flamesong
08-20-2009, 10:59 AM
I have found an answer.

Apparently (I say this as it is all new to me), the URL of the include has to be defined as 'virtual' as opposed to 'file'. Once done, I was able to use the relative, i.e. '../../' addresses.

However, I had to change all the URLs of images which were included in the includes to absolute, i.e. 'http://www.'

So far, so good. No doubt there will be more to learn.