Apache allows you to configure server side includes (SSI) to add dynamic web content, html code, and reuse them more efficiently. In this article, we will look at how to enable server side includes (SSI) in Apache.
What is Server Side Includes (SSI)?
Server Side Includes (SSI) allow you to include files (other than header files) in your web pages. They are mainly used to serve dynamic content on web pages and reuse HTML codes. For example, you can create a navigation bar/footer for your website, put it in a separate file and include it on all your web pages.
Also read : How to Disable ETags in Apache
How To Enable Server Side Includes (SSI) in Apache
Here are the steps to enable server side includes in Apache.
1. Open .htaccess or server configuration file
Before proceeding, please enable mod_rewrite (.htaccess) in your Apache web server.
Open .htaccess file, typically located at /var/www/html/.htaccess
$ sudo vi /var/www/html/.htaccess
Alternatively, if you have access to Apache configuration file, you can open it
$ sudo vi /etc/apache2/httpd.conf
Also read : How to Fix Request URI Too Large in Apache
2. Enable Server Side Includes
Add the following line to .htaccess.
AddType text/html .html AddHandler server-parsed .html Options Indexes FollowSymLinks Includes
If you have opened server configuration file, add the following lines
Options +Includes AddType text/html .html AddOutputFilter INCLUDES .html
The above lines enable server side includes and instructs apache to look for server side includes in .html files. You can enable server side includes for other file types (e.g .shtml) also by adding following lines.
AddType text/html .shtml AddHandler server-parsed .shtml
Also read : Apache Restrict Access to URL by IP
3. Restart Apache web server
Restart Apache web server to apply changes.
# service httpd restart OR # systemctl restart httpd OR # sudo service apache2 restart
4. Verify Server Side Includes
Add the following line to any of your php web page (e.g /index.php) to dynamically display today’s date on it.
<!--#echo var="DATE_LOCAL" -->
Open browser and go to http://your_domain_or_ip/index.php. Replace your_domain_or_ip with your domain or ip address. You will see today’s date displayed at the same location where you added the above code.