|Making PHP pages SE friendly|
Needing advice on some code...
Being a total novice to server side scripting (and working with someone else to build a mysql/php set up), I've found the following piece of code which apparently allows you to keep the page extensions as html, but forces the webserver to treat html pages as php pages without any variables passing through the URL (eg page.html?a=b&c=a+b):
AddType application/x-httpd-php .html .htm .php
Does anyone have any experience with this, if so does it work or are there some pitfalls. I was going to produce a static html site from our database but use the php in the background for functionality; but if this avoids the need to do that it maybe useful (i think!). Any advice would be much appreciated. TIA. Stuart.
I've used this on some sites without problems, but it's worth bearing in mind that by default PHP pages will include a server header of X_Powered_by_php in every page, identifying it as a dynamic page.
Whether this has any effect on the way search engines treat the page I don't know - I've not seen any yet.
Generally I produce static pages as you were considering, just to be on the safe side - would it be a major task to do that on your site?
Thanks sugarkane, I guess we'll go the static html site/php functionality route to be safe, which was the initial idea.
I know its a never ending question but whilst i'm here and because we're so new too this can i ask if you have any general tips or know any major pitfalls to this sort of set up?
We currently produce static pages offline using templates and a java pagebuilder, but whats the best set up if we have a mysql database online (sychronised in parts offline).
How longs a piece of string, right!?!
> How longs a piece of string, right!?!
Hehe, that's about right ;)
Much depends on the design of your site. In my case I build the site in Perl or PHP, using modules / includes to provide the templates.
Rather than using a single dynamic 'display' page that pulls data from a database (eg display.php?product=1), I use individual files that act as a wrapper for the display routines - eg file product1.php would simply consist of:
All internal navigation points to these wrapper pages rather than the actual pages that generate the dynamic content, so there's a fully spiderable site structure there that doesn't rely on query strings. Whether this structure is the main navigation of the site or done through building a site map is up to you.
At this point you could use the AddType 'trick' to name the pages as .html, but I use a Perl script to spider the site and save the spidered pages as static html, adjusting the internal links from .php to .html, which effectively generates a static 'mirror' of the site. Once functionality is required (eg 'add to cart'), the original PHP pages take over.
All this is done on the development server, and I then transfer the whole lot to the production server.
I'm sure there are many other approaches but I've found this one to be the most effective for me.
Thats great sugarkane, thanks for taking the time to reply, its early stages for us at the moment so its really helpful to hear how people are doing these things. Thanks very much.
I use php parsed in the .html extension and have had no problems. I always use a modular setup that doesn't use a templated page just includes headers, footers, menus etc so I can keep maintenance to a minimum. I also do a similar setup to sugarkane, staying away from query strings all together and passing vars inside the page or posting them if necessary.
I didn't realize the header info, thanks sugarkane, the thought actually never crossed my mind.
Apparently the x-header can be got rid of via a compile option in PHP, but that's probably not an option for most of us. Does anyone know of a different way? An Apache config option possibly?
i use php with the .html on all my pages. There is a way to get rid of the php header, you could probably do it with the .htaccess file. or if you had access the to php config file you could change the php mode to invisible. (I think that would work)
as far as i know search engines dont care about the php in a pages, and there are many more widely used methods of finding if a page was dynamically created. This goes back to the http specification, if you are interested in knowing I will go on.
If you are going to be using php in all your pages any ways, the only problem I can see with the .html is deleting or causing an error in your .htaccess file could cause a lot of damage, including revealing the pass and username for your database. I know the odds are slim if you are using a production server but it could happen. There are ways around this if you would like to hear about it.
I donít want to keep you too long,
Thanks Brendon, please do go on with both points though if you don't mind, about the http specification and protecting the .htaccess file; at this stage all practical experience is really helpful. TIA. Stuart.