URL rewriting possible in Busybox httpd?

Roman Krüger amdahl256 at googlemail.com
Thu Feb 19 13:32:58 UTC 2009


2009/2/19 Denys Vlasenko <vda.linux at googlemail.com>:
> I don't understand what do you want to achieve.
>
> Do you want to just output data/foo/bar/bla/blubb file
> from httpd root directory to the peer? This is easy.
>
> Or do you want to feed this rewritten URL back
> to httpd, so that it can decide whether this is a file, a script,
> a directory and so on? This is not implemented.



I think my first example was a bit "inverted".

Ok, a better description:

For example you have a shop system.
It works with a CGI. You can access the page for a certain product with the URL:

http://192.168.0.1/cgi-bin/shop?category=42&product=23

Now you don't want that the user knows that it works with a CGI or script
and you don't want him to see /cgi-bin/ and the ugly ? & = characters in the
URL. It should just look like a static path and document.

So the user types the URL:
http://192.168.0.1/shop/category/42/product/23/
in his address bar, the URL will be internally rewritten to
http://192.168.0.1/cgi-bin/shop?category=42&product=23

so that the CGI can do its work with the two parameters and values.

This is done nowadays with many weblogs, forums or shops.
See http://en.wikipedia.org/wiki/URL_rewriting for another description.


If this feature is not implemented in Busybox, I could just patch httpd.c
at the place where it checks for "cgi-bin/" in the URL, check for my
rewritten URL fragment and give the part after this fragment to my CGI. I would
then just parse foo/bar/bla/blubb instead of foo=bar&bla=blubb.
This would be only a few lines of code.

bye
Roman


More information about the busybox mailing list