Forum Moderators: coopster
Should I use one index.php file (per section which includes header, footer, content) and which then includes various content files in an array depending on which is called (product.html, product2.html, etc.), or should each prouct be a product.php, product2.php with the includes built into each of those php files.
Any help would be greatly appreciated.
I wasn't sure if that was defeating the purpose of PHP by having all those seperate PHP files.
This will mean more work though because this used to be an I-Frames website so all the .html files are setup as just the content which would work nicely for the other option.
My fear of using one index.php was what if someone used an old link mypage.html link, they would only see the content, not the .php page. And also for Google, I had no idea how it would index.
Thanks.
So I add this to my .htaccess file:
RewriteEngine on
RewriteRule ^(.*)\.html $1\.php
I currenlty have these files:
product1.html (product content which loads in frames)
product2.html (product content which loads in frames)
product3.html (product content which loads in frames)
and I then need to create these files with the same names as the html files:
product1.php
product2.php
product3.php
and for example the product1.php file would contain the following code:
<?php $content = "../product1.html";
include $_SERVER['DOCUMENT_ROOT'] . "/includes/template.php";
?>
and my includes folder would have seperate files for:
header.html
footer.html
template.html
with my template.php file containing:
<div class="header">
<?php include $_SERVER['DOCUMENT_ROOT'] . "/includes/header.html";?>
</div>
<div id="main">
<?php include $content;
?>
</div>
<div class="footer">
<?php include $_SERVER['DOCUMENT_ROOT'] . "/includes/footer.html";?>
</div>
and now when someone types in www.mypage.com/product1.html
they are directed to
www.mypage.com/product1.php
so long as there's a corresponding .php file where any .html file (or link to one) used to be, it all works swimming. old inbound links are none the wiser. you could also add an [R=some number] code (see here [httpd.apache.org] for more details, [R=301] would be a "permenantly moved") to the end of the rule to setup a redirect to the .php if you like, as it stands, the user sees page.html in their browser address bar, which I quite like!
perhaps it doesn't go without saying, because the html files are "include"(d), they can in turn contain valid php code, even if your server is set to parse .html as plain old html.
$content = 'product1.html'; would be fine, too, if it's in the same folder as the .php file, and I don't even think both the backslashes in the rule are strictly necessary either, but it certainly works! A large chunk of my site uses this rewrite rule, folks find the htm versions (where the content is) with my search engine, and that leads them straight to the php file that displays that content.
for sites upgrading from static to php pages, I just can't think of a finer way to do it.
have fun!
;o)
(or