Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite difference between [R] and [P]

         

jino

2:17 am on May 26, 2004 (gmt 0)

10+ Year Member



I have java servlets which works well with rewrites.

RewriteEngine on
RewriteRule ^/plist/(.*)/(.*)/(.*) /cms/servlet/amazon?Subject=List&mode=$1&KeywordSearch=$2&page=$3 [P]

This works fine for
/plist/books/baby/1

translate to

/cms/servlet/amazon?Subject=List&mode=books&KeywordSearch=baby&page=1

However if I have a phrase keyword(2 words with space in between), I get an error.

/plist/books/baby%20diet/1

This phrase error does not occur if my rewrite rule uses the [R] mode instead of [P] mode. I prefer to use the proxy mode because it's not so confusing for the user.

Can anyone help me out here? Thanks.

jdMorgan

3:07 am on May 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jino,

[R] and [P] are two very different things. [R] invokes an external 302 (Moved Temporarily) redirect, sending the new URL back to the client browser, which will then re-request the resource with that URL. [P] invokes the proxy module, which acts as a surrogate for the client, and requests and returns the resource as if it were accessible with the original URL. Neither of these methods are very efficient, and you might want to try doing a simple URL rewrite instead (leave off both the [R] and [P], and use a local URL-path substitution). Here's what it would look like (along with two other small changes to speed up the code a bit):


RewriteRule ^/plist/([^/]*)/([^/]*)/(.*) /cms/servlet/amazon?Subject=List&mode=$1&KeywordSearch=$2&page=$3

Even if you decide to stick with your current method, take a look at RewriteRule's [NE] (NoEscape) flag -- That might help fix your %20 problem. You also might consider changing those spaces to hyphens; Hyphens are treated as spaces by most search engines, and don't cause the trouble that spaces and other special characters can cause.

Jim

jino

11:54 am on May 26, 2004 (gmt 0)

10+ Year Member



Jim,

Thanks for the reply. I tried the local rewrite without the [R] or [P] and got a 404 error.

When I put back the [R] or [P] it was OK.

I tried the [NE] with no luck.

Couple of questions:

If I were to use [R], would the SE recognize the original URL or the redirected URL?

What is the difference between [R] & [R=301]?

Which should I use in this case?

Thanks in advances.

jdMorgan

2:26 pm on May 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jino,

Please see the mod_rewrite documentation [httpd.apache.org] for information on the RewriteRule flags.

I've never used java servlets, so I don't fully understand you application, but you may also need to use the [T] flag to identify the MIME-type of your servlets to the browser when using an internal rewrite.

If you use [R], [R=301], or [R=302], then the client (browser or SE spider) will use the new URL that you redirected to - and this is probably not what you want.

If this were my site, I would put a lot of effort into making an internal redirect work without using mod_proxy, in order to avoid a decrease in server performance.

Jim