2

I want to include header into many webpages So I want to create a single file and include in all the pages. There is one way that I found is by SSI (server side include) but it require changing extension of webpage from Html to sHtml(that I cannot do due to some restriction).

Is there any way to do this without changing extension?

rajnish
  • 750
  • 1
  • 10
  • 17

3 Answers3

0

Last time I checked (which was a number of years ago), with Apache, if you made the html files executable by httpd process, they would act like shtml, without having to rename them.

I leave the security implications of doing this to your own evaluation.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
  • The XBitHack is the better method nowadays. Better options in more recent years. – donlaur Jan 08 '13 at 22:24
  • I looked at the XBitHack directive, and it sounds exactly like what I described. What's the difference? – GreyBeardedGeek Jan 08 '13 at 23:47
  • Big difference. Having all html files as SSI means that each file has to be run from the server as SSI. Using the Xbit sort of marks html files as .shtml to the server so that they know which files to process with SSI. If you only have a few files maybe not much difference but for large sites with many files it can affect load time. – donlaur Jan 08 '13 at 23:54
0

You can use jQuery/AJAX approach

$.get('ajax/test.html', function(data) {
$('.result').html(data);
alert('Load was performed.');
});

Reference: http://api.jquery.com/jQuery.get/

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • I tried this, It is working on IE, Safari but not on Chrome and Mozzila. I am getting this error **Origin null is not allowed by Access-Control-Allow-Origin** – rajnish Jan 09 '13 at 22:28
  • Is this similar to what you are trying to do? http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin – James A Mohler Jan 09 '13 at 22:30
0

Your best methods are PHP files with includes. SSI works well, but you have to have the .shtml file.

Non recommended methods would be using an iframe to include the header. Javascript can also be used but it isn't good to use client side includes. jQuery would also be client side includes.

You can set .html files to use SSI but if you have restrictions this is most likely a restriction that you can not get past. Hosted server accounts do not allow this for the most part.

Apache Server docs on SSI. http://httpd.apache.org/docs/current/howto/ssi.html

To permit SSI on your server, you must have the following directive either in your httpd.conf file, or in a .htaccess file:

Options +Includes This tells Apache that you want to permit files to be parsed for SSI directives. Note that most configurations contain multiple Options directives that can override each other. You will probably need to apply the Options to the specific directory where you want SSI enabled in order to assure that it gets evaluated last.

Not just any file is parsed for SSI directives. You have to tell Apache which files should be parsed. There are two ways to do this. You can tell Apache to parse any file with a particular file extension, such as .shtml, with the following directives:

AddType text/html .shtml AddOutputFilter INCLUDES .shtml One disadvantage to this approach is that if you wanted to add SSI directives to an existing page, you would have to change the name of that page, and all links to that page, in order to give it a .shtml extension, so that those directives would be executed.

The other method is to use the XBitHack directive:

XBitHack on XBitHack tells Apache to parse files for SSI directives if they have the execute bit set. So, to add SSI directives to an existing page, rather than having to change the file name, you would just need to make the file executable using chmod.

chmod +x pagename.html A brief comment about what not to do. You'll occasionally see people recommending that you just tell Apache to parse all .html files for SSI, so that you don't have to mess with .shtml file names. These folks have perhaps not heard about XBitHack. The thing to keep in mind is that, by doing this, you're requiring that Apache read through every single file that it sends out to clients, even if they don't contain any SSI directives. This can slow things down quite a bit, and is not a good idea.

donlaur
  • 1,269
  • 1
  • 12
  • 21
  • In my directory there is no file ".htaccess" so I have created a new file and added these lines: XBitHack full chmod +x index.html I have added include in my index page(index.html) : but it is still not working. Please let me know if I am doing something wrong or missing something. – rajnish Jan 09 '13 at 22:17