Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having a CGI script catch all requests to a domain with Apache

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.

like image 873
Jotham Avatar asked May 19 '09 06:05

Jotham


2 Answers

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
like image 98
Greg Avatar answered Oct 13 '22 00:10

Greg


(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.

like image 29
Jotham Avatar answered Oct 12 '22 23:10

Jotham