Updating Identical Content Across Domains
For site owners with several domains, some content may be identical across domains. This may be contact information or a contact form, as examples.
Updating each one individually and verifying they're all correct can be time consuming. Unless all domains import the identical content from one central file. Then, updates are relatively easy.
There are several ways to import the content.
Importing Content With PHP
Create a central file containing the content that must be identical on all domains. Upload it to your server and make a note of its URL.
Put this PHP code on the web pages where the information is to be published (change the
<?php readfile("http://example.com/centralfile.html"); ?>
If your PHP does not allow the readfile() function to use http://... URLs, ask your hosting company to enable fopen wrappers. (More information at this page.)
Importing Content With JavaScript
Use the the Text to JavaScript Converter. Either upload the converter web page to your website or use the example installation linked from the above article.
Use the Text To JavaScript Converter to convert the content that must be identical on all domains.
-
Save the converted JavaScript to a file with a .js file name extension.
-
Upload the file to your server.
-
Make a note of the .js file's URL.
Next:
-
Copy the JavaScript to import the file that the converter also provides.
-
Change the src URL to the URL of the .js file on your server.
-
Paste the JavaScript to import the file on the web pages where the information is to be published.
Importing Content With SSI and CGI
SSI can not import content from a different domain. But CGI can. Therefore, a CGI programed is installed on each domain that the SSI can import from.
First, create a central file containing the content that must be identical on all domains. Upload it to your server and make a note of its URL.
Now, install the following CGI script on each domain, in a directory that can run Perl CGI scripts (instructions follow).
#!/usr/bin/perl $URLofCentralFile = 'http://example.com/centralfile.html'; use LWP::Simple; print "Content-type: text/html\n\n"; print get($URLofCentralFile); exit;
To install:
-
Copy the above code and paste it into a plain text processor like NotePad or TextWrangler.
-
Replace the
http://example.com/centralfile.html URL in the script to the URL of the central file created earlier. -
Save the file with a .cgi file name extension.
-
Upload the file to your server with FTP as a plain text file (not as a binary file).
-
Give the uploaded file 755 permissions.
Test each installation by typing its URL into your browser.
Make a note of the script's URI as it will be needed for the SSI tag. The URI is the URL minus the domain name information. Example: URL
Here is an example SSI tag to put on the web pages where the information is to be published (replace
<!--#exec cgi="/cgi-bin/contentscript.cgi"-->
The SSI tag executes the script. The script grabs the central file and sends it to the web page with the SSI tag.
If the above SSI tag doesn't work (some hosting companies block the SSI "exec" command), try this code (again, update the URI).
<!--#include virtual="/cgi-bin/contentscript.cgi"-->
Importing identical content into several domains from one central file can save a lot of time otherwise spent updating each domain separately.
Will Bontrager