Forum Moderators: coopster
Long story short, I have a website which is in two parts: the informational .html pages and the ecommerce shopping cart (php pages).
While setting up this cart, I learned php and css for the first time and now understand how useful they are.
However, my html pages have been created (not all of them, I do want to expand the site to MANY pages).
I am fine with how to deal with creating a css stylesheet for my html pages. No problems there.
But now I want to implement such things as creating a separate navigation file so I just update the one file when adding new pages to the site and not updating each page individually. Note, the navigation links on my html pages are different than those of my cart, so I will need to create a new file and not use the existing one from the cart. Are ya confused yet? LOL.
Now, from my limited understanding - the moment you add one snippet of php to a hmtl, you must change the page ext from .html to .php. Is this correct?
I also just read this evening in one of the threads here that if you change your pages from html to php, then you will have seo problems.
So, can I do a php-like function on a html without having to change the extension?
I tried the
<?php include('nav.html')?> into my index.html page but it did not work. Is it because my page is still .html? What other alternatives do I have? I do not know enough about php to actually create .php pages on my own. Granted, my html pages are basic html, nothing fancy at all.
I've tried reading php tutorials, but have yet to find one that answers questions about using php in html pages and such.
Any suggestions would be greatly appreciated. I want to get set up right with the 6 html pages I have right now so when I go to add more and more pages, I'm set up from the get-go. I am looking to have hundreds of pages within the year (not including the shopping cart pages!).
If you want your pages to be parsed as PHP you need to tell the HTTP Server (Apache) to parse file extensions as such. The manual pages you are looking for are the Installation [php.net] pages. There is also an Installation FAQ [php.net] that is very handy to keep bookmarked.
And finally this is actually what you will need in order to parse your pages. You usually only need to update a couple of lines in your Apache httpd.conf. The links provided here have this information but I'll throw it down here for clarity:
# PHP 4
# This solution doesn't work for Apache 1 as PHP module doesn't catch php-script.
AddHandler php-script htm html php
# You may have to use this instead:
# AddType application/x-httpd-php htm html php
AddType text/html php
# PHP 5
AddHandler php5-script htm html php
AddType text/html php
AddType application/x-httpd-php .html .php .php5 s.php4 .php3 .phtml Instead of parsing PHP files with the HTML engine, aren't we looking for parsing HTML files with the PHP engine? Is your code a result of the new hooks into PHP that Apache 2.x has?
Does the code you posted maybe have an additional performance value, in your opinion of the new Apache capability?
Thanks.
AddType application/x-httpd-php .html .php .php5 s.php4 .php3 .phtml
keep in mind that this way every html-file will be fed through php, meaning it will probably be at least 10 times slower - probably no big deal, bt if you have millions of pages spider traffic alone could be able to kill your server.
To avoid this, you could do ot the other way round:
instead of passing myexample.html though php, rename it myexample.php - this way it will be parsed by php without adding anything - and use mod.rewrite to make it look like it is still named myexample.html to the outside world. This way only the are pased by php that you want to.
Coopster, I've got a different perspective illustrated in my own config files. (Apache 1.x-2.x)
StupidScript,
There are big differences between AddType and AddHandler. jdMorgan effectively reduces the differences to a simple sentence in this Apache Forum thread that questions why Application types cause problem [webmasterworld.com]? Yes, AddType will indeed work for defining the handler in PHP installations but is not how it should be handled according to an Apache bug [issues.apache.org]. By the way, the links on that bug page provide some excellent reading and discussion on the topic.
I have spent hours researching this subject especially when it come to content negotiation and the correct configuration directives to get it all working properly. The PHP developers have added an Installation FAQ [php.net] since the issue first rose. On Apache 2.x I no longer use AddType to set the handler. I use the AddHandler method described earlier.
It all comes down to the internals of the Apache http server and the PHP module written for it and how it was written. You can peel apart some of the source code for both to get into the gory details ;)