Httpd – Hide redirects using mod_rewrite

httpdmod-rewrite

I'm using mod_rewrite to rewrite GET requests to a particular script.

My Goal is to redirect the request for:

http://localhost/Work/dbUI/pageElements/Dialog/Contact.php?id=138750

to

http://localhost/Work/dbUI/pageElements/Dialog.php?dialog=Contact.php&id=138750

I'm using:

RewriteEngine On
RewriteLog "/var/log/rewrite"
RewriteLogLevel 3
RewriteCond %{THE_REQUEST} /Work/dbUI/pageElements/Dialog/
RewriteCond %{QUERY_STRING} id=([^&?]*)
RewriteRule (.*) http://localhost/Work/dbUI/pageElements/Dialog?dialog=Contact.php&id=%1 [R=302]

It works quite well; but when I make the request I get the following headers (this is the output of a cURL routine):

* About to connect() to localhost port 80 (#0)
*   Trying 127.0.0.1... * connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /Work/dbUI/pageElements/Dialog/Contact.php?id=138750 HTTP/1.1
Host: localhost
Accept: */*

< HTTP/1.1 302 Found
< Date: Tue, 09 Nov 2010 21:37:54 GMT
< Server: Apache/2.2.16 (Fedora)
< Location: http://localhost/Work/dbUI/pageElements/Dialog?dialog=Contact.php&id=138750
< Content-Length: 338
< Connection: close
< Content-Type: text/html; charset=iso-8859-1

As you can see, I get a 302 and a Location header that redirects the client. Is it possible to simply serve the content as opposed to a redirect to the content? The goal is to mask the actual URL for the content.

When I try adding replacing [R=302] with [L] I get the following output in my rewrite log:

127.0.0.1 - - [09/Nov/2010:16:55:27 --0500] [localhost/sid#137cfb0][rid#160fc90/initial] (2) init rewrite engine with requested uri /Work/dbUI/pageElements/Dialog/Contact.php
127.0.0.1 - - [09/Nov/2010:16:55:27 --0500] [localhost/sid#137cfb0][rid#160fc90/initial] (3) applying pattern '(.*)' to uri '/Work/dbUI/pageElements/Dialog/Contact.php'
127.0.0.1 - - [09/Nov/2010:16:55:27 --0500] [localhost/sid#137cfb0][rid#160fc90/initial] (2) rewrite '/Work/dbUI/pageElements/Dialog/Contact.php' -> 'http://localhost/Work/dbUI/pageElements/Dialog?dialog=Contact.php&id=138750'
127.0.0.1 - - [09/Nov/2010:16:55:27 --0500] [localhost/sid#137cfb0][rid#160fc90/initial] (3) split uri=http://localhost/Work/dbUI/pageElements/Dialog?dialog=Contact.php&id=138750 -> uri=http://localhost/Work/dbUI/pageElements/Dialog, args=dialog=Contact.php&id=138750
127.0.0.1 - - [09/Nov/2010:16:55:27 --0500] [localhost/sid#137cfb0][rid#160fc90/initial] (2) implicitly forcing redirect (rc=302) with http://localhost/Work/dbUI/pageElements/Dialog
127.0.0.1 - - [09/Nov/2010:16:55:27 --0500] [localhost/sid#137cfb0][rid#160fc90/initial] (1) escaping http://localhost/Work/dbUI/pageElements/Dialog for redirect
127.0.0.1 - - [09/Nov/2010:16:55:27 --0500] [localhost/sid#137cfb0][rid#160fc90/initial] (1) redirect to http://localhost/Work/dbUI/pageElements/Dialog?dialog=Contact.php&id=138750 [REDIRECT/302]
127.0.0.1 - - [09/Nov/2010:16:55:27 --0500] [localhost/sid#137cfb0][rid#160fc90/initial] (2) init rewrite engine with requested uri /Work/dbUI/pageElements/Dialog
127.0.0.1 - - [09/Nov/2010:16:55:27 --0500] [localhost/sid#137cfb0][rid#160fc90/initial] (3) applying pattern '(.*)' to uri '/Work/dbUI/pageElements/Dialog'
127.0.0.1 - - [09/Nov/2010:16:55:27 --0500] [localhost/sid#137cfb0][rid#160fc90/initial] (1) pass through /Work/dbUI/pageElements/Dialog

Best Answer

Try this: In your RewriteRule, replace the [R=302] flag with [L].