Globally define parts of virtualhost definition to reduce redundancy

Posted by user1428900 on Stack Overflow See other posts from Stack Overflow or by user1428900
Published on 2012-06-20T15:12:55Z Indexed on 2012/06/20 15:15 UTC
Read the original article Hit count: 137

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about apache

Related posts about virtualhost