Forcing www in url using Apache

To enforce www to every url, we can use mod_rewrite module in apache.
The idea is to make only one entry point to your site e.g.
1. www.techpitcher.com
2. http://techpitcher.com
3. http://techpitcher.com/index.html
4. www.techpitcher.com/index.html
As listed above there are at least 4 ways to access the home page of the site. To make one access url like http://www.techpitcher.com, we need to configure apache’s configuration file.
To use this method, you must have write access to your apache’s configuration file.

1. Open httpd.conf file. In case of Apache2, this can be a blank file.
2. Verify that mod_rewrite.so moule is loaded, Then load mod_rewrite.so module.
LoadModule rewrite_module /mod_rewrite.so
3. Below is piece of code which will force www in every url

<VirtualHost www.techpitcher.com:80>
	DocumentRoot /home/techpitcher/public_html
	ServerName www.techpitcher.com
	ServerAlias techpitcher.com
	RewriteEngine On
	RewriteCond %{HTTP_HOST} ^www\.techpitcher\.com
	RewriteRule ^/index\.html$ http://www.techpitcher.com/ [R=301,L]
	RewriteCond %{HTTP_HOST} ^techpitcher\.com
	RewriteRule ^/(.*) http://www.techpitcher.com/$1 [R=301,L]
</VirtualHost>

R[=code] Redirect to new URL, with optional code. Usually you also want to stop and do the redirection immediately. To stop the rewriting you also have to provide the ‘L’ flag.

java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException

I am getting following exception while using httpclient.

</p>
<p>java.lang.NoClassDefFoundError:org/apache/commons/codec/DecoderException<br>
at org.apache.commons.httpclient.HttpMethodBase.&amp;lt;init(HttpMethodBase.java:216)<br>
at org.apache.commons.httpclient.methods.GetMethod.&amp;lt;init(GetMethod.java:88)</p>
<p>

Please tell me why am I getting this exception?

Compression using mod_deflate in Apache

A compression filter optimizes the size of the content that you send from your web server to a user via the Internet. This will save lots of bandwidth and so the application will be a lot faster as the content will be transfered to browser pretty soon. This task can be performed by turning mod_deflate module on.
To set mod_deflate I added following block in httpd.conf, This file can be found in /conf/httpd.conf.

1. Load deflate_module module. It might be commented in the beginning of the file. Uncomment if commented.

LoadModule deflate_module modules/mod_deflate.so

2. Set compression filter

<Location />
  <IfModule mod_deflate.c>
   SetOutputFilter DEFLATE
  # file-types indicated will not be compressed
   SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip|pdf)$ no-gzip dont-vary
    <IfModule mod_headers.c>
      Header append Vary User-Agent
    </IfModule>
  </IfModule>
</Location>

3. Create a new log file to check compression results, it can be done by placing following code in httpd.conf. You need to make sure that mod_log_config is included in httpd.conf.

<IfModule mod_log_config.c>
  <IfModule mod_deflate.c>
    DeflateFilterNote Input instream
    DeflateFilterNote Output outstream
    DeflateFilterNote Ratio ratio
    SetEnvIf Request_URI \.gif image-request
    SetEnvIf Request_URI \.js image-request
    SetEnvIf Request_URI \.css image-request
    LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
    CustomLog logs/deflate.log deflate env=!image-request
  </IfModule>
</IfModule>

I have verified compression with & without ssl mode and don’t find any problem.

Technology