Forum Moderators: coopster & phranque

Message Too Old, No Replies

Rewrite all pages

Want to rewrite all files in all directories

         

mdharrold

3:13 am on May 20, 2002 (gmt 0)

10+ Year Member



I have been using a nph-script for all of my rewrites by setting it as the 404error document.

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)

Brett_Tabke

11:41 pm on May 20, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



What does the error log say?

I'd know how to fix it (one line for each directory), but I think little would be able to give you a one liner. (what's happening, is it is try to go to /directory/cgi-bin/.... it's tacking on the other directory name when you call it)

mdharrold

8:50 pm on May 21, 2002 (gmt 0)

10+ Year Member



When I call any page that is in another directory, it is giving a 404error.

I thought about doing an entry for each directory, but there has to be an easier way.

mdharrold

11:44 am on May 22, 2002 (gmt 0)

10+ Year Member



I got this to work by having several different Rewrite rules:

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>

physics

8:22 pm on Jul 1, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi. I think this should do it (it works for me):

RewriteRule ^.*$ cgi-bin/nph-script.cgi [L]

However, I am having trouble with the fact that this does not seem to work for cgi-bin pages. What I want mod_rewrite to do is if it sees
foo.com/choo/moo/goo-woo.html
it rewrites it to a script and sends the url as information like this:

RewriteRule ^(.*)$ cgi-bin/test.pl/$1 [L]

(THIS PART WORKS)
BUT I also want that to work for
foo.com/cgi-bin/program/info
However, instead of rewriting it it seems to just give me the output of that program. Suggestions?

mdharrold

9:02 pm on Jul 1, 2002 (gmt 0)

10+ Year Member



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.

physics

9:30 pm on Jul 1, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's the thing about rewrite isn't it... it's so darn confusticating. I have no problem with normal directories with dashes such as
foo.com/test-dir/normalfile.html
even with
RewriteRule ^(.*)$ cgi-bin/test.pl/$1 [L]

But when I try it on cgi-bin it won't work... even if I add an explicit rule for cgi-bin !!

physics

11:30 pm on Jul 1, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I did find a work around for the cgi-bin thing. I'd rather have a directory called 'exec' or something like that masquerade as cgi-bin with a rewrite rule anyway. Thus I tried the following:

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!