Monthly Archives: September 2012

Apache: Realative Link Problem using Rewrite Engine (mod_rewrite)

Using the Apache Rewrite Engine there might occour a problem with relative links if you are e.g. are jumping between directories or if you are using the the Rewrite Engine for an internal proxy. In the follwing example realtive links in the page will not work properly.

  <Directory "/documentroot/de">
  RewriteEngine on
  RewriteBase    /de/
  RewriteRule    ^/?  http://localhost/?language=de  [P]

There is a very easy solution to avoid this problem. You can define a base url tag in the header section of your HTML pages.

In the example above you have to include something like follows to the header section of all pages that do not work properly:

   <base href="http://localhost/">


That’s ist!

Wt Web Toolkit: Get URL parameter string values

If you want to access an url parameter string in Witty C++ HTML Web Toolkit there is an easy way to do so. Imagine you want to get the content of the parameter “param” in a URL like To do so you can use the following code in your Wt Application class:

#include <Wt/WApplication>
#include <Wt/WEnvironment>
#include <string>
#include <iostream>

using namespace Wt;

class myApplication: public WApplication
  myApplication(const WEnvironment& env)
    : WApplication(env)
    setTitle("This is an application");

    addMetaHeader ("description","a description");

    const std::string* param =    this->environment().getParameter("param"); 

    if (param!=0)
        std::cout << (*param) << std::endl;



Also have a look of the handling of internal paths in Wt Web Toolkit:

Apache: Convert URL parameter strings to directories for search engine friendly URLS

Imagine you have a URL like which looks pretty ugly. For Search Engine Optimization it would be nice to have a more search engine friendly URL like

Apache offers an easy way to hide the parameter string by the second URL format. However, internally the page still is treated like the first version of the URL but users and search engines will not notice the old URL format.

To implement the example from above you simply have to add the following lines to your httpd.conf .

In this example the directory en is forwarded internally to page.php?language=en. If the user enters he will see the content of without noticing the parameter string.

<Directory "/documentroot/en">

  Options Indexes FollowSymLinks

  AllowOverride All

   Order allow,deny
   Allow from all

  Options +FollowSymlinks
  RewriteEngine on

  RewriteCond %{REQUEST_URI} =/en/

  RewriteRule   ^/? page.php\?language\=en [PT]


In the line /documentroot/en you define the directory for which you want to apply the hack. It has to be the internal location at your server.

The line “RewriteCond %{REQUEST_URI} =/en/” tells Apache to apply the hack only if is requested. Other URLs in the directory like will not be touched.

How to use Apache as a proxy server

The following configuration allows you to make Apache forward the request for your domain to a second domain at port 8081. If the user enters “” in his browser he well see the content provided by the server listening at 

<VirtualHost *:80>
    ServerAlias *
    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    ProxyPass /
    ProxyPassReverse /
    <Location />
        Order allow,deny
        Allow from all