Page 1 of 1

RewriteRule matching filename not url in substitution

PostPosted: 28. October 2012 17:24
by brainchild
I wrote a CGI script (in python) that transforms XML files into XHTML for display in the client.

It is invoked as follows: http://hostname/path/scriptname.py?p=filename.xml

However, I much prefer a cleaner URL to be seen by the client: http://hostname/path/filename

The solution seems to be a RewriteRule directive. Since I am using shared hosting, I do not have access to httpd.conf. However, I am able to create an .htaccess file in the /path directory.

Creating such a file in the /path directory, it would seem that the correct rule is:
RewriteRule ^(.+)$ index.py?p=$1.xml

Strangely, when this rule is executed for the above clean version of the path, $1 is actually set to "index.py", not "filename". This is useless, because I already know the name of the script. What I don't know is the final component of the request URL. How can I fix the rule to set $1 to "filename"?

Thanks.