I am testing G-WAN server and I’d like using rewrite rules.
With apache the rule is :
RewriteRule ^(.+)-(.+)-(.+)-1.jpg$ imagesproduitnew/$3/$2.jpg [L]
I am trying to do it by handlers JPG, but I have lot of difficulties.
Has anybody already done something like that ?
My handlers is called url_wr.c in the path /0.0.0.0_80/#0.0.0.0/handlers
Here is the script
int init(char *argv[], int argc);
int main(int argc, char *argv[])
{
const long state = (long)argv[0];
if(state == HDL_AFTER_READ)
{
xbuf_t *read_xbuf = (xbuf_t*)get_env(argv, READ_XBUF);
xbuf_replfrto(read_xbuf, read_xbuf->ptr, read_xbuf->ptr + 16, "/blog", "/?blog");
}
return 255; // execute next connection step
}
int clean(char *argv[], int argc);
In gwan.log, it is not writen loaded url_wr.c
If I put printf in each function, it doesn’t work.
The servlet bloc.c works well.
I also tried tu put the code in handlers/main.c and in the root of gwan directory.
I have only a error.log file for the site which says just error404 without any details of the handlers.
Thanks by advance for your support
You must use a G-WAN
connection handler, either to use:OR,
regexlibrary (libc provides regex calls) if you target a more general rewrite scheme. Here is an example in C and the explanations are there, courtesy of “Regular Expressions in C” from the “Linux Gazette”.This could also be made rom a
servlet, but then you would have to trigger a redirection (unless the resource was explicitely placed into a cache). If this is acceptable, then v3.10+ will let you do it in C#, PHP, Python, etc.UPDATE following the code published in the question:
Your
init()call is empty somain()is never called. You should do this instead:Also, make sure that
connection handlersare namedmain.c. In contrast,content handlerscarry the name of the targeted file extension (gif.c, html.c, etc).