Globally define parts of virtualhost definition to reduce redundancy
- by user1428900
I have setup an apache server and this apache server points to a bunch of virtualhosts.
The definition of the virtualhosts are as follows,
<VirtualHost *:80>
ServerName <url>
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
# Enable client-side caching of resources
ExpiresActive On
ExpiresByType image/png "now plus 48 hours"
ExpiresByType image/jpeg "now plus 48 hours"
ExpiresByType image/gif "now plus 48 hours"
ExpiresByType application/javascript "now plus 48 hours"
ExpiresByType application/x-javascript "now plus 48 hours"
ExpiresByType text/javascript "now plus 48 hours"
ExpiresByType text/css "now plus 48 hours"
</VirtualHost>
.
.
.
<VirtualHost *:80>
ServerName <url>
RewriteEngine on
ReWriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
# Enable client-side caching of resources
ExpiresActive On
ExpiresByType image/png "now plus 48 hours"
ExpiresByType image/jpeg "now plus 48 hours"
ExpiresByType image/gif "now plus 48 hours"
ExpiresByType application/javascript "now plus 48 hours"
ExpiresByType application/x-javascript "now plus 48 hours"
ExpiresByType text/javascript "now plus 48 hours"
ExpiresByType text/css "now plus 48 hours"
</VirtualHost>
I have a ton of virtual host definitions similar to the examples shown above.
Since, most of the definitions other than the ServerName are the same, I was wondering if there was a way to define these common definitions globally.
I am new to apache configuration and I felt that as the number of virtualhost definitions increase my configuration file becomes longer and redundant.