Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite problem

         

DrDoc

5:49 am on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Say that I have a site whose document root is: /home/blah/path/to/some/sub/folder
Now, I want to point this script to /home/blah/otherscript.php

Can that be done? The folders all have the same user and permissions. It just happens that one domain's document root points to a subfolder of a different domain... and now I need to access a parent folder from the domain...

DrDoc

7:52 am on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, I have it partially working (and tell me if this is the right way of going about what I want to do)...

RewriteEngine on

RewriteCond %{REQUEST_URI} ^/somefolder
RewriteRule (.*) http://www.otherhost.com/$1 [P]

That works great if I try to access http://www.myhost.com/somefolder/file.php
But, if the file has a query string (http://www.myhost.com/somefolder/file.php?foo=bar) it returns a 404 error :(

gergoe

11:42 am on Aug 11, 2004 (gmt 0)

10+ Year Member



You can try this one:

RewriteEngine on
RewriteRule ^/somefolder/(.*) http://www.otherhost.com/$1 [P,QSA,L]

The difference is that I merged the RewriteCond and the RewriteRule together (the first parameter of the RewriteRule is tested against the requeqt uri, so you don't really need the separate RewriteCond fro this purpose). And I added the QSA flag, which might solve the query string problem (although i'm not sure about this, because yours should have been working without this also). Try adding the Options +FollowSymLinks ahead of the mod_rewrite directives in the htaccess file, that might solve the problem.

Although my approach to this problem would be something like this:


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/somefolder/file.php$ /home/blah/otherscript.php [L]

The difference is that it only rewrites a specified php script (if I understand your first post that's what you want), and it uses filename-to-filename rewriting, so the apache does not need to fetch the requested file through the proxy module.

Brett_Tabke

12:13 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



umm, try something like this. Notice the end cmd that tells apache that it is a script.

RewriteRule /fred/foo/t.htm /bar/t.cgi [T=application/x-httpd-cgi]

DrDoc

1:53 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the replies, both of you.

FollowSymLinks is already on... and QSA didn't make a difference as far as the query string goes. The reason why I run it through the Apache proxy is because the script has to be run under the other domain, even though I want to display the output on a different domain.

So a local rewrite won't work (or else I would've just set up manual sym links)...

The weird thing is that everything works when there's no query string present... which tells me there's something wrong in the qs parsing. Apache seems to think that the qs is part of the file name :(

Any other ideas?

jdMorgan

1:57 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What do the access and error log files of the servers show when it fails?

Jim

DrDoc

2:11 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Access log

Success:
*.*.*.* - - [11/Aug/2004:07:46:57 -0600] "GET /info.php HTTP/1.1" 200 52298 "-" "User-Agent"

Failure:
*.*.*.* - - [11/Aug/2004:07:48:58 -0600] "GET /info.php?foo=bar HTTP/1.1" 404 418 "-" "User-Agent"

Error log

[Wed Aug 11 07:48:58 2004] [error] [client *.*.*.*] File does not exist: /path/to/some/file/info.php?foo=bar

DrDoc

2:24 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've tried stripping out the query string...

RewriteRule ^([^\?]*).* http://www.otherhost.com/$1 [P]

...but that makes no difference

jdMorgan

2:39 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> What do the access and error log files of the servers show when it fails?

Anything in your error log for accesses using your original code version?

If you are proxying to another server, look at the access and error logs of both servers.

Jim

DrDoc

2:43 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Same physical machine...
The error log is shared between the vhosts...
Access log for the other host shows nothing fun.
200 OK when the rewrite works... Nothing when it doesn't

DrDoc

3:02 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And, what bugs me even more...

If I hardcode it:

RewriteRule .* http://www.otherhost.com/info.php [P]

http://www.myhost.com/info.php works well...
http://www.myhost.com/info.php?foober=blick does not...

http://www.myhost.com/gaaaah.php (a script that doesn't exist) works well too... redirecting to info.php like it should

gergoe

3:54 pm on Aug 11, 2004 (gmt 0)

10+ Year Member



Try following to take out the query string explicitly:

RewriteRule ^/([^?]*)(\?.*)?$ http://www.otherhost.com/$1$2 [P,L]

In your case I might try out the normal (not these tweaked) rules with telnet or a Server Header Check tool, it sounds to me that something with the uri passed to the server is not properly formed (or the proxy module is got mad, did you tried it w/o the Proxy flag?)

bakedjake

3:59 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Doc, in what order are you loading the php, proxy, and rewrite modules?

DrDoc

4:10 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



take out the query string explicitly

Well, I realized a bit ago that mod_rewrite doesn't include the query string in the RewriteRule statements...

Umm, from what I can tell it loads mod_rewrite first, then mod_proxy, then php...

bakedjake

4:40 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Load proxy before rewrite, see if that helps.

DrDoc

4:45 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dang!

That did the trick! I owe you big time, Jake :)