Rewrite? Alias?

software development

#1

I have a tricky problem that I’m hoping someone here knows how to handle.

I need to route a bunch of different “script names”, that could be preceded by random paths, to a single script.

For instance, one url might be

http://mydomain.com/[color=#CC0000]2006/4[/color]/[color=#0000CC]monthlisting[/color]?display=thread&page=1

and another might be

http://mydomain.com/[color=#CC0000]2006/4/12[/color]/[color=#0000CC]article[/color]?id=3

They all need to go to the same script (which is technically a fastcgi executable). The script, in turn, will look at the path (shown in red) and the script name (shown in blue), and the parameters and go from there. I don’t need help with the part that happens within the script, just the way to set up .htaccess to route all of those urls to the single script.

BTW, there will be a limited number of script names (so each can be given a line in .htaccess), but there could be any number of paths.

I have done this before, on a web server where I had access to httpd.conf…this is what I added:

FastCGIServer /usr/local/apache2/fastcgi-bin/myapp -port 9014

and then

AliasMatch //article /usr/local/apache2/fastcgi-bin/myapp
AliasMatch /
/monthlisting /usr/local/apache2/fastcgi-bin/myapp

which worked great. But I don’t have access to httpd.conf here, and don’t have the ability to configure fastcgi any way I want.

Any ideas how I can accomplish this? Can this be done with a rewrite rule? I know there aren’t too many fastcgi people here, but I imagine that most of the techniques would apply to other things as well.

Thanks for any help…

-rob


#2

Frameworks do this all the time. They route everything through index.php and goto work from there. This is a copy of my .htaccess file with my work on Zend Framework:

[quote]RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !.(js|ico|gif|jpg|png|css)$
RewriteRule (.*) index.php [QSA,L][/quote]
-d and -f insures the file doesn’t exist to begin with. And the last check makes sure it’s not of them type of files. If all checks, it then rewrites everything to index.php. No [R] which means it’s not a redirect, the user does not see the rewrite.


yerba# rm -rf /etc
yerba#


#3

Thank you thank you thank you!

Works beautifully. The only thing I needed to change in my script (compared to my old way, with AliasMatch) is that now, I need to look at the environment variable “SCRIPT_URL” instead of “SCRIPT_NAME” (since I need the actual url they entered, to get the path and name and such).

I guess I also will need to make it write a proper 404 page if I determine that the URL they entered isn’t valid, but that’s no big deal.

-rob

http://karmatics.com