Forum Moderators: phranque

Message Too Old, No Replies

mod rewrte issue with Apache

mod_rewrte issue

         

Ninad

10:17 am on Oct 10, 2008 (gmt 0)

10+ Year Member



We are tryig to use mod_rewrite module provied by Apache to rewrite URLs on encountering specific URI's

Our current architecture is that we have Apache Proxy Server which forwards their requests to the Web Logic Portal Managed Servers. All the business Logic resides on Web Logic Portal. Apache Proxy is just for request forwarding.

Now we require that any request that comes with a URI of /xyz/*/a.htm should be rewritten using the mod_rewrite module to a URI as /test/xyz/*/a.htm : Now we referred the online docuemntation for using this and did the following entries in the httpd.conf file:

-------------------------------------------------------------
RewriteCond %{REQUEST_URI} ^/xyz/(.*)
RewriteRule ^(.*)$ /test$1 [R]
---------------------------------------------------------------

and this worked .. i.e any URL with a pattern /xyz/*/a.htm is getting redirected to /test/xyz/*/a.htm . But there is a problem here and the problem is that we have "[R]" written on second line of httpd.conf file . Just wanted to know what does this signify. We do not want to use this as we presume it is an HTTP redirect , but the functionality fails if we remove "[R]" from the line above . Why is it necessary to use the "[R]" setting . Can we work without this .

Please let us know if there is a better way to achieve the functionality above:

g1smd

11:29 am on Oct 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The [R] is for a 302 redirect; you can also use [R=302] for that.

A 301 redirect would use [R=301] instead. Most times that you need a redirect, 301 is the one you need.

A redirect forces the browser to make a new HTTP request for a new URL.

Without the R, and specifying only a local filepath, you get a rewrite.

A rewrite is different to a redirect. The browser doesn't see a URL change. They get what they asked for at the same URL they requested.

g1smd

11:35 am on Oct 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If it really is a rewrite you want, then this should work, in your .htacess file:

RewriteRule ^xyz/(.*) /test/xyz/$1 [L]

Add a leading / before xyz if the rule is to be used in httd.conf.

Before the rewrite, make sure you are also doing the standard domain and file canonicalisation stuff (strip index files, redirect non-www to www, etc) otherwise you expose the files at multiple URLs.

You'll also need to redirect calls for /test/xyz(.*) over to http://www.example.com/xyz$1 using a 301 redirect, so that the files cannot be directly accessed via the /test/ folder as a direct URL.

Ninad

11:54 am on Oct 10, 2008 (gmt 0)

10+ Year Member



Hi All ,
Thanks a lot for your replies. Working in (.htaccess) file means that folder should be present on my apache itself . But in my case I want to redirect to a folder on Web Logic Portal Server . In that case what is the option available. Also could you please ping me a link for doing this .htaccess configuartion. I am really new to this Apache system.

Regards ,
Ninad

jdMorgan

1:32 pm on Oct 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want content served from a different server, but do not want to redirect to that server and expose its URL in the visitor's browser address bar, then you need to set up your main server as a revers proxy for these requests. This is a non-trivial project, so I suggest spending a lot of time here [httpd.apache.org] before starting.

See Apache mod_proxy and associated tutorials, as well as looking at all the other server configuration stuff. Configure *only* a reverse proxy -- Enabling a forward proxy is unnecessary, and presents a serious security risk unless many details are attended to.

Jim