views:

287

answers:

4

Hi,

Using Apache 2, I want to configure my website so that any requests to the domain are forwarded to a Python CGI script. Basically, if the user goes to http://www.example.com i want the cgi /cgi-bin/cgi.py to execute. If the user goes to http://www.example.com/index.rss I want /cgi-bin/cgi.py to be executed with /index.rss as the argument. I have tried various combinations of ScriptAlias and Rewrite and cannot seem to get them in the right relationship.

A: 

While it's not 100% what you're looking for, here's the .htaccess I use for an old abandoned domain of mine to redirect people properly. It basically redirects for any file or directory not found in the local directory structure. It's up to the script itself to figure out what url it was called for:

RewriteEngine On

#if the request isn't for a file or a directory...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Fuzzy76
A: 
RewriteEngine On

RewriteRule ^(.*)$ /cgi-bin/cgi.py?url=$1

This will redirect ALL requests to your python file. If you're having trouble with the script alias still, try adding the passthrough flag [PT] at the end of the RewriteRule line If you still want to be able to access images etc then add this before the RewriteRule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Greg
+1  A: 

(not sure on the correct procedure with answering ones own question - but...)

Looks like I was having conflict with ScriptAlias and RewriteRule. In the end the solution was to use AddHandler to create a relationship then use mod_rewrite to pull everything into the CGI. And RewriteCond to avoid catching /resources/ and /media/. My VirtualHost now looks like this:

AddHandler cgi-script .cgi
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/resources/.*$
RewriteCond %{REQUEST_URI} !^/media/.*$
RewriteRule ^(.*)$ /cgi-bin/pyblosxom.cgi$1 [L]

Thanks for your help guys.

Jotham
A: 

I used the capturing rewrite rule and it worked to a degree. The problem was that original query string of the request URI wasn't passed to the cgi when using $1. I ended up removing the capture and just referencing ENV['REQUEST_URI'] in my cgi script to gain access.

Brad