Add www to URL using Apache mod_rewrite

For sites belonging to a domain name(Not Subdomain), one can access the site using the domain name with www, Ex: www.example.com or without it: example.com

Both ways the site can be accessed when a ServerAlias is created in the config. However this is confusing as session information for both is different, which means if one is accessing the site with www preceded and logs in, on accessing the site without www preceded - the server would have no information saved.

To redirect any domain name to use www by default, the following mod_rewrite condition can be used:

Disabling Munin and Awstats

Munin is a server and network monitoring tool. AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. This log analyzer works as a CGI or from command line and shows you all possible information your log contains, in few graphical web pages.

Sometimes both can result in High Server i/o due to its periodic cron tasks. Uninstalling via command line wont help as you may see cron based tasks for Munin and Awstats running in logs.

Apache Benchmarking


Apache benchmarking is a tool used for benchmarking apache based websites.

The syntax for anonymous users:
ab -c no_of_concurrent_users -n no_of_requests_per_user URL

To capture the benchmarking information for authenticated users, we need to capture the cookie information for any authenticated user from the browser and provide it in a name=pair cookie value in the command

ab -c no_of_concurrent_users -n no_of_requests_per_user -C cookie_name=cookie_value URL

The data we are interested in looking for benchmarking is:

Apache Tuning


Enable Mod Expires
Drupal states via .htaccess that if mod_expires is on, it caches all files for 2 weeks. This means that the browser would cache static content.

Set KeepAlive On For Apache to wait until all the elements of a page requests are provided.

MaxKeepAliveRequests -> How many download requests per page.. [Check with Firebug]

KeepAliveTimeOut 15 --> How many seconds required for the page to load completely in the browser. 4 sec is a good threshold.

Apache URL Redirection on VPS

I faced an issue with redirecting a particular URL to another URL at the Apache settings. You can write an index.php(php based solution) file for redirecting the header to the required URL. However, this didnt seem to me like an apt solution hence I looked for a solution at the Apache Config itself.

Considering you have a VPS where you have configured the virtual host as follows:

ServerName pr.example.com
ServerAlias pr.example.com
DocumentRoot /sites/www/pr.example.com/public_html/
ErrorLog /sites/www/pr.example.com/logs/error.log