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.
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
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With