Lana has asked for the wisdom of the Perl Monks concerning the following question:

Hi :-)

Is there a way to send request to external perl script by adding some mod_rewrite condition and then, depending on script response, apply some rewrite rule?

I need something like this:

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond IF SCRIPT /home/cgi-bin/ckw.cgi\?%{REQUEST_URI} RETURNS 1 RewriteRule ^.*$ (rewrite rule goes here) [L] </IfModule>
Why do I need that? I have a MySQL database with keywords. When visitor clicks some link on my website, RewriteCond condition sends request to that ckw.cgi script with %{REQUEST_URI} as a query string. Script parses the request URI, search for keywords used in REQUEST_URI through database and returns 1 or 0. If it returns 1 - RewriteRule is applied for this link, elsif it returns 0 - no rules applied.

Is there a way to do this? My English is not perfect but I hope you understand me.

Thanks, Lana

  • Comment on Getting response from external script by Apache mod_rewrite condition
  • Download Code

Replies are listed 'Best First'.
Re: Getting response from external script by Apache mod_rewrite condition
by moritz (Cardinal) on Feb 21, 2008 at 09:48 UTC
    You can use a rewrite map, and use an external program. Scroll down to External Rewriting Program, that should be exactly what you are looking for.

    But note that it is not handled as a CGI script, but uses its own, simple conventions.

      I know about RewriteMap but this not solves my problem as it doesnt allow to proceed to the next RewriteCond/RewriteRule through .htaccess file if there is no match in the database.

      Maybe there some other solution?