I would now like to just use mod_rewrite to send all requests to the script so that even the /index.html page runs through the script.
I have:
RewriteEngine on
RewriteRule ^$ /cgi-bin/nph-script.cgi [L]
working to rewrite the index.html page, but whenever there is a call for any page in another directory, I get a 500 error.
Ideas?
(Apache 1.3, Unix box, virtual hosting)
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^$ /cgi-bin/script.cgi?index [L] #takes care of site.com
RewriteRule ^([a-z]+)$ /cgi-bin/script.cgi?$1 [L] #takes care of site.com/page
RewriteRule ^([a-z]+)/$ /cgi-bin/script.cgi?$1 [L] #takes care of site.com/directory/
RewriteRule ^([a-z]+)-([a-z]+)/$ /cgi-bin/script.cgi?$1-$2 [L] #takes care of site.com/directory-name/
RewriteRule ^([a-z]+)-([a-z]+)/([a-z]+)$ /cgi-bin/script.cgi?$1-$2/$3 [L] #takes care of site.com/directory-name/page
This works for me for now, but if I used underscore instead of hyphen, I would then need another rule for that.
Still looking for an easier rewrite rule.
<added>If I do come up with a rule that will rewrite for anything, what happens if I upload a page that does not require the rewrite? Will it still be rewritten?
If so, maybe I don't want to rewrite every page.</added>
RewriteRule ^.*$ cgi-bin/nph-script.cgi [L]
RewriteRule ^(.*)$ cgi-bin/test.pl/$1 [L]
Hi. I think this should do it (it works for me):RewriteRule ^.*$ cgi-bin/nph-script.cgi [L]
That worked for me too except when the file or directory contained a hyphen. (Which would also explain your cgi-bin problem)
Maybe
RewriteRule ^.*-.*$ cgi-bin/test.pl/$1-$2 [L]
RewriteRule ^.*$ cgi-bin/test.pl/$1 [L]
would fix it.
RewriteRule ^(.*)$ cgi-bin/test.pl/$1 [L] RewriteRule ^(.*)$ cgi-bin/test.pl/$1 [L]RewriteRule ^exec/(.+)$ /cgi-bin/$1 [L]
This did work.
Now
foo.com/exec/program/info
causes
cgi-bin/test.pl/program/info
as well as the normal
foo.com/index.html
causing
cgi-bin/test.pl/index.html
It must have something to do with the way that Apache handles cgi-bin.
Looking in my httpd.conf seems to support this theory:
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client. <Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
mdharrold:
I still don't know why you are having trouble with dashes, sorry!