Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite to cgi

         

Kastro200

7:30 pm on Sep 25, 2009 (gmt 0)

10+ Year Member



Hello,

First of all I`d like to say hi since this is my first post here.

So basically I have an assignment to configure apache server.

When a user makes a request e.g. www.home.com/subdir/hot/dog
it would internally process this request like - www.home.com/cgi/cgi.exe/hot?dog.
The cgi.exe could be something as simple as displaying "Hot" and "Dog" in html.

Well I thought i did it -

RewriteEngine ON
RewriteRule ^subdir/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ /cgi-bin/CGI.exe/$1?$2 .. plain and simple :)

But as I discovered I needed to use server variables: QUERY_STRING and PATH_INFO where in this example PATH_INFO = hot and QUERY_STRING = dog.

So heres the problem I don`t really know how to apply this.
I have been searching web for hours and I still can`t find a working code.

My guess would be that it`s something like this:

RewriteCond %{PATH_INFO} ^/subdir/([A-Za-z0-9-]+)/$
RewriteCond %{QUERY_STRING} ^([A-Za-z0-9-]+)$
RewriteRule (no idea) /cgi-bin/CGI.exe/%1?%2

Could someone point me to the right direction?

Thanks.

jdMorgan

9:26 pm on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On Apache 2.x, just rewrite all of /subdir to your script, or use ScriptAlias to essentially do the same thing. Then set the PathInfo option (look up ScriptAlias and PathInfo directives in the Apache documentation, and yes, if you're going to 'configure a server' you'll need to read it.)

Having done that, you *use* the PATH_INFO variable *inside* your cgi script to get the parts of the requested URL-path that weren't used getting to the script.

I'm not sure where you got the idea that you needed to use QUERY_STRING and PATH_INFO in your rewrite rule... Your description of your project requirements do not support that idea.

As long as you have set Options +FollowSymLinks, and as long as your rule above was located in the Web root .htaccess file (the directory where your 'home page' would be if it were a static html file), then your code should have worked. It should also have worked within a <Directory /> container inside a server config file like httpd.conf. However, if the code is inside a config file, but not inside a <Directory> conmtainer, then you will need to add a slash to the rewriterule pattern; In that case only, the requested URL-path will be seen to start with a slash.

Also be aware that although changes to .htaccess files take effect immediately, you will have to restart your server for changes to config files to take effect.

Jim