PDA

View Full Version : completely transparent redirect to port 9000?


Mashi
05-15-2007, 10:06 AM
Hi,

I'm trying to make the redirect process for php5 files completely transparent (since I'd like to be able to use REQUEST_URI to get details of the request).

My .htaccess is as follows:


RewriteEngine On

# Pass any enquiries that aren't for static files over to server on port 9000 (php5)
RewriteCond %{SERVER_PORT} !9000
RewriteCond %{SCRIPT_FILENAME} !(css|js|jpg|gif|png)
RewriteRule ^(.*)$ http://%{HTTP_HOST}:9000/$1 [P]

# Direct everything on this port to index.php
RewriteCond %{SERVER_PORT} 9000
RewriteRule ^(.*)$ index.php [L]


The idea is that any requests that aren't for static files get passed "as they are" to port 9000, and then I can have my usual rewriterules for any request on port 9000.

However using this I get a 400 proxy error:

Your browser sent a request that this server could not understand.
The proxy server could not handle the request GET /index.php.
Reason: URI cannot be parsed: http://mashi.org:9000:9000/index.php

Making a request for the index.php file directly works as expected (http://www.mashi.org/index.php), though.

Any idea why it's adding the port on twice?

Thanks

edit: Just a note, the browser isn't being redirected:
Browser:
GET /fds HTTP/1.1
Host: www.mashi.org
Server:
HTTP/1.x 400 Proxy Error

Mashi
05-15-2007, 03:19 PM
Also, the following results in a redirect loop (change underlined):

RewriteEngine On

# Pass any enquiries that aren't for static files over to server on port 9000 (php5)
RewriteCond %{SERVER_PORT} !9000
RewriteCond %{SCRIPT_FILENAME} !.*\.(css|js|jpg|gif|png)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}:9000/$1 [P]

RewriteCond %{SERVER_PORT} 9000
RewriteRule ^(.*)$ http://%{HTTP_HOST}:9000/index.php [L]

This is what the loop looks like:

Browser:

GET /index.php HTTP/1.1
Host: mashi.org:9000

Server:

HTTP/1.x 302 Found
Location: http://mashi.org:9000:9000/index.php

Matt
05-15-2007, 03:25 PM
RewriteCond %{SERVER_PORT} !9000
RewriteCond %{SCRIPT_FILENAME} !\.(css|js|jpg|gif|png)$
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule ^(.*)$ http://%{HTTP_HOST}:9000/$1 [L,P]


There you go.

Mashi
05-15-2007, 03:51 PM
This solves the proxy error but then the REQUEST_URI is lost after the second RewriteRule (example (http://www.mashi.org/fds)).

The .htaccess is as follows (removing the L flag from the 1st has no effect):

RewriteEngine On

RewriteCond %{SERVER_PORT} !9000
RewriteCond %{SCRIPT_FILENAME} !\.(css|js|jpg|gif|png)$
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule ^(.*)$ http://%{HTTP_HOST}:9000/$1 [P]

# have to negate this RewriteCond for the next rule to take effect at all
#RewriteCond %{SERVER_PORT} 9000
RewriteRule .* index.php [L]


Strangely, the REQUEST_URI is kept here: http://www.mashi.org/index.php/fds.

Mashi
05-15-2007, 04:08 PM
Many thanks to the guys on IRC, this turned out to be the solution:


RewriteEngine On

RewriteCond %{HTTP_HOST} !9000
RewriteCond %{SCRIPT_FILENAME} !\.(css|js|jpg|gif|png)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}:9000/$1 [L,P]

RewriteCond %{HTTP_HOST} 9000
RewriteRule .* index.php [L]


Working great!