Change shtml page to php

305 Views Asked by At

I have a site with pages with shtml extension, primarily done to have menu navbar display corrctly with SSI. I now am adding a page with php, and to have this page work properly I have given it a php extension, which causes the menu to no longer display. I also frankly find the shtml extension to be an odd one for most who use my site. I would like to change to php extension for all pages if possible, but how do I reformat my SSI to display properly if I no longer use the shtml extension?

The current code of interest is <!--#include virtual="/Navbar.shtml" -->

3

There are 3 best solutions below

2
On BEST ANSWER

It should just be a matter of changing your Server side include code to

<?php require "/Navbar.php" ?>

and renaming Navbar.shtml to Navbar.php

Require means that there is an error and the page wont load at all if Navbar.php is missing. You could also use include, which is similar, but will allow the page to load. Read the following manual pages for more info on include and require.

http://www.php.net/manual/en/function.include.php
http://php.net/manual/en/function.require.php

Hope this helps :)

1
On
<!--#include virtual="/Navbar.shtml" -->

to

<?php require '/Navbar.php' ?>
1
On

If you include a local file using SSI, the static source file will be used - in this case, the unparsed PHP source code.

You would have to do a remote include for this to work (something like <!--#include virtual="http://localhost/Navbar.shtml" -->, depending on server configuration). That is not optimal, because a new server request, and a PHP instance, are started.

It would be better to drop SSI for this, and use a PHP include as @Alin shows.