Forum Moderators: coopster

Message Too Old, No Replies

E-Commerce Webiste -Several .PHP files or one Index.php?

should I use one index.php for a whole section of Html content pages?

         

Flash72

10:22 pm on May 28, 2004 (gmt 0)

10+ Year Member



For my e-commerce website the pages are all the same except for the product content in the center which changes.

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.

ogletree

10:41 pm on May 28, 2004 (gmt 0)

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



I would have them be seperate pages. You can name them product1.php and product2.php. You will get spidered better and you will get some value in having the links have the product name in them.

Flash72

11:19 pm on May 28, 2004 (gmt 0)

10+ Year Member



Thank You.

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.

ogletree

4:42 am on May 29, 2004 (gmt 0)

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



Google can index the one page as many and does. I know people that do what you do and rank very well. I have seen it go the other way from experience and I know other people in the same boat. I just would not try it if SEO is important.

WhosAWhata

5:51 am on May 29, 2004 (gmt 0)

10+ Year Member



don't forget, Mod_rewrite enabled apache servers have that as an option too

ogletree

6:36 am on May 29, 2004 (gmt 0)

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



I forgot about that. You should do that. You can do both that way.

WhosAWhata

7:28 pm on May 29, 2004 (gmt 0)

10+ Year Member



if you need help with this, let me know or check out the apache forum [webmasterworld.com]

corz

3:37 am on May 30, 2004 (gmt 0)

10+ Year Member



yeah, keep the html, use some mod_rewrite magic. see here [webmasterworld.com]

;o)
(or

Flash72

9:20 pm on May 31, 2004 (gmt 0)

10+ Year Member



This sounds brilliant!

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

corz

3:39 am on Jun 1, 2004 (gmt 0)

10+ Year Member



yup! cool, isn't it?

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