After reading through many threads of this Apache forum as well as the .htaccess tutorial in Apache Docs at [
httpd.apache.org...] I've realized I have untapped performance tweaks that I can apply to my VPS. I'd like to post some proposed changes that I want to implement and would appreciate feedback to confirm that I'm understanding this properly, am using proper syntax, and that they would be beneficial changes.
I've taken almost a year to fiddle around with many things on my VPS to be sure I know enough about hosting to be competent (enough) to safely and securely host client websites post-development. Up until now my "oops" moments affected nobody but me. But, I'm now bringing client websites to my VPS from scattered 3rd party hosts so all applied changes must work properly on the first try. These are locally or regionally focused commercial sites with a steady flow of traffic from motivated buyers.
While those sites were hosted on 3rd party shared plan hosts I applied as much performance enhancements as possible through .htaccess files where required modules were enabled and/or allowed. I'm referring primarily to gzip/deflate compression and browser caching. But now I've learned that I can save CPU resources by moving those same directives directly into the httpd.conf files and disable .htaccess altogether. This is a totally managed service I am providing for non-technical owners who take a totally hands-off approach to their internet presence. They don't need, or even want, access to anything server side. It's great for me because it allows me to secure so much of the environment by denying access to so many features.
Ok to the point...
Typical my individual www.example.com/.htaccess files look like this with slight variations from one domain to another:
--------------------------------------------------------------
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 2 hours"
ExpiresByType text/php "access plus 2 hours"
ExpiresByType text/xml "access plus 2 hours"
ExpiresByType text/plain "access plus 2 hours"
ExpiresByType text/inc "access plus 2 hours"
ExpiresByType application/x-javascript "access plus 60 days"
ExpiresByType application/js "access plus 60 days"
ExpiresByType text/css "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/ico "access plus 1 year"
ExpiresByType application/pdf "access plus 1 year"
</IfModule>
<FilesMatch "\\.(php|css|html|htm|xml|txt|js)$">
SetOutputFilter DEFLATE
</FilesMatch>
--------------------------------------------------------------
In the /etc/apache2/apache2.conf there is a line indicating "Include /etc/apache2/httpd.conf"
So I'd like to move the following to /etc/apache2/httpd.conf from multiple www.examples.com/.htaccess
ExpiresActive on
ExpiresDefault "access plus 2 hours"
ExpiresByType text/php "access plus 2 hours"
ExpiresByType text/xml "access plus 2 hours"
ExpiresByType text/plain "access plus 2 hours"
ExpiresByType text/inc "access plus 2 hours"
ExpiresByType application/x-javascript "access plus 60 days"
ExpiresByType application/js "access plus 60 days"
ExpiresByType text/css "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/ico "access plus 1 year"
ExpiresByType application/pdf "access plus 1 year"
<FilesMatch "\\.(php|css|html|htm|xml|txt|js)$">
SetOutputFilter DEFLATE
</FilesMatch>
In the above, can I omit the <IfModule mod_expires.c> because I have root access and know it is enabled unlike on 3rd party hosts where I didn't know and therefore had to test for it? I'm assuming if it doesn't have to check it will save some CPU? Also, if I apply it at the /etc/apache2/httpd.conf level will it cascade down through all virtual domains in the VPS container?
-----------------------------------------------------------------
Next would be the redirecting example.com traffic to www.example.com
Can I consolidate all virtual host info into the /etc/apache2/httpd.conf file such as:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain_1.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain_2.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain_3.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Do I need to leave the "Options +FollowSymLinks" statement in or is that intended for the .htaccess version?
Also, am I right or wrong to modify RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] by adding a "
/" such as RewriteRule ^
/(.*)$ http://www.example.com/$1 [R=301,L] to compensate for difference between .htaccess version and httpd.conf version?
Or should I put the redirect traffic directives in individual config files at individual vhost levels such as: /var/www/vhosts/example.com/conf/httpd.include (wherein there is an "Include /var/www/vhosts/example.com/conf/vhost.conf" directive):
So that /var/www/vhosts/example.com/conf/vhost.conf is like:
Options +FollowSymLinks (<----- with or without?)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^
/(.*)$ http://www.example.com/$1 [R=301,L]
--------------------------------------------------------------------
Last point would be that I will then disallow .htaccess by commenting it out in apache2.conf and so therefore I have to
remember to delete the .htaccess files from each domain root to prevent 500 errors on server reboot!
As always, feedback and/or constructive critizism is greatly appreciated. I'd like to implement these changes in the wee hours of the weekend when traffic is null because I know I have to reboot the container after changes are applied in order for them to take effect. Leisurely responses are welcomed, much thanks in advance :)