Snippets code from my daily experience

June 24, 2007

Simulating top level domains on localhost

Filed under: apache_httpd — dafi @ 8:44 am

On my local Apache test server I’ve configured many fake TLDs that take their contents from different directories (DocumentRoots).

But I found the problem to allow web browser to serve the correct content.

For example if I type the url http://dafizilla.stage I want to get content from /dafi/stage/dafizilla

if I type the url http://svn.myjavasrc I want to get content from /dafi/src/svn

Obviously dafizilla.stage and svn.myjavasrc are fake TLD and they are hosted on same Apache Server on my localhost.

Well the solution is to use Apache VirtualHost.

Add to /etc/hosts on Linux or C:/WINDOWS/…/etc/hosts on Windows the fake TLDs for localhost dafizilla.stage svn.myjavasrc

Then define in httpd.conf the VirtualHosts:

NameVirtualHost localhost

<VirtualHost localhost>
DocumentRoot /dafi/stage/dafizilla
ServerName dafizilla.stage
ErrorLog logs/stage-dafizilla-host-error_log

<VirtualHost localhost>
DocumentRoot /dafi/src/svn
ServerName svn.myjavasrc
ErrorLog logs/svn-host-error_log

The browser inserts into HTTP headers the domain name that is lookedup by Apache server


June 22, 2007

Using UTF-8 with Apache and Jboss

Filed under: apache_httpd,java,jboss,utf-8 — dafi @ 2:26 am

I’ve found a strange problem with my first real UTF-8 web application…

The urls sent in GET didn’t decoded properly and I was very astonished, my code was written correctly but the problem was present.

BTW the problem wasn’t on my code but in Jboss (in Tomcat embedded instance).

The connector must have the attribute URIEncoding otherwise the webapp never will work.

Due to the fact I use mod_jk (ie AJP13 protocol) this lifesaver attribute must be added in AJP13 connector, too

I love when problems disappear modifing only a configuration file 🙂

For sanity check I’ve added UTF-8 support also in Apache Server but I suspect this isn’t really necessary 😉

In http.conf be sure to have the AddDefaultCharset directive set as shown below

AddDefaultCharset utf-8

Create a free website or blog at