PB program to handle Mod_Rewrite (rewriting URLs)

Everything else that doesn't fall into one of the other PB categories.
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

PB program to handle Mod_Rewrite (rewriting URLs)

Post by Seymour Clufley »

Has anyone done this?

I'm just beginning with Mod_Rewrite but Xampp is playing up so I can't do any testing (yet), so in the meantime I'd like to know if anyone else has succeeded in doing this.

You can read about it here. It's an article about implementing mod_rewriting in your site's htaccess file. Normally this is done with the RewriteCond and RewriteRule functions, but you can also pass the duty to an external program, including executables apparently...
External Rewriting Program

MapType: prg, MapSource: Unix filesystem path to valid regular file

Here the source is a program, not a map file. To create it you can use the language of your choice, but the result has to be a executable (i.e., either object-code or a script with the magic cookie trick '#!/path/to/interpreter' as the first line).

This program is started once at startup of the Apache servers and then communicates with the rewriting engine over its stdin and stdout file-handles. For each map-function lookup it will receive the key to lookup as a newline-terminated string on stdin. It then has to give back the looked-up value as a newline-terminated string on stdout...
That sounds like the operation of a CGI executable except there's only one input variable and the program has to loop constantly, checking if the input variable has changed.

There are a few things I need to know...
  • Do PB programs qualify as "object-code executables"? According to this definition, it would seem they do.
  • Would the executable have to be compiled for Linux even if the server was Windows-based? (Silly question perhaps but I'm asking because the above article specifies "Unix filesystem path".)
  • How do you get a stdin variable? I know how to get CGI variables using GetEnvironmentVariable("VARIABLE_NAME") but this seems a little different. There doesn't seem to be a "forum consensus" on how to do this. ReadConsoleData()?
  • How to detect if the input variable has changed?!
Thanks for any help,
Seymour.
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

No news as yet. I've joined a forum dedicated to mod_rewrite, and the resident guru says that what I want to do is possible. However, that forum has gone offline due to bandwidth restrictions so no more help from that guru for a while!

If I do succeed, I'll post the code and detail any requirements that must be in place for it to work. Such will apply only to Apache running on Xampp.

In the meantime, I'm having trouble getting Apache to communicate with the PB url-rewriting app. I'm worried it might be because of how I've implemented STDIN. I've written another app in PB which calls the rewriter and communicates with it using WriteProgramString - the rewriter receives these strings no problem, using ReadConsoleData. Is that what is meant by STDIN?
Post Reply