[Semi-OT] mod_rewrite and $r->parsed_uri

[Semi-OT] mod_rewrite and $r->parsed_uri

am 08.04.2005 12:30:08 von Thomas Klausner

Hi!

Is it possible to somehow get to the URI as it looks like after beeing
transformed by mod_rewrite?

What I'm trying to do is:

In a DB I have 'pseudo-files' with a column named 'path' and titles and
bodies in several languages. (title_de, title_en, etc)
Values for 'path' are eg: '/index.html', '/foo/bar.html'

I have a RewriteRule like this:
RewriteRule ^/(en|de)/(.*) /$2?lang=$1 [QSA,PT]

And a handler that takes what is in $r->parsed_uri->path and does a DB
lookup with the value.

The problem is that after mod_rewrite $r->parsed_uri->path returns
'/de/index.html'.

What am I missing?

--
#!/usr/bin/perl http://domm.zsi.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

Re: [Semi-OT] mod_rewrite and $r->parsed_uri

am 08.04.2005 15:25:30 von Geoffrey Young

Thomas Klausner wrote:
> Hi!
>
> Is it possible to somehow get to the URI as it looks like after beeing
> transformed by mod_rewrite?

don't you just want $r->uri?

>
> What I'm trying to do is:
>
> In a DB I have 'pseudo-files' with a column named 'path' and titles and
> bodies in several languages. (title_de, title_en, etc)
> Values for 'path' are eg: '/index.html', '/foo/bar.html'
>
> I have a RewriteRule like this:
> RewriteRule ^/(en|de)/(.*) /$2?lang=$1 [QSA,PT]
>
> And a handler that takes what is in $r->parsed_uri->path and does a DB
> lookup with the value.

I don't think anyone is supposed to (or traditionally does) mess with
$r->parsed_uri. it's usually $r->uri and $r->filename.

>
> The problem is that after mod_rewrite $r->parsed_uri->path returns
> '/de/index.html'.
>
> What am I missing?

I'm almost entirely sure what you're looking for is in $r->uri, especially
with the PT option. translation is a URI-to-filename mapping, so
essentially what your rule is doing is mucking with $r->uri and then letting
the next handler think $r->uri is what came from the browser. there's even
a comment in mod_rewrite to this effect.

if that doesn't work we can try another thought pattern :)

--Geoff

[OT] Thoughts (Re: [Semi-OT] mod_rewrite and $r->parsed_uri)

am 08.04.2005 20:02:18 von Joe Schaefer

Geoffrey Young writes:

> if that doesn't work we can try another thought pattern :)

Or just buy a new video card- sometimes it's hard to tell the
difference ;-)

--
Joe Schaefer

Re: [Semi-OT] mod_rewrite and $r->parsed_uri

am 08.04.2005 21:42:16 von Thomas Klausner

Hi!

On Fri, Apr 08, 2005 at 09:25:30AM -0400, Geoffrey Young wrote:

> > Is it possible to somehow get to the URI as it looks like after beeing
> > transformed by mod_rewrite?
>
> don't you just want $r->uri?

Yes. Thanks.

> I don't think anyone is supposed to (or traditionally does) mess with
> $r->parsed_uri. it's usually $r->uri and $r->filename.

Well, in the mod_perl Cookbook you (or one of your co-authors) mess with
$r->parsed_uri (eg Recipe 5.3 'Altering the Request URI' page 160ff)

I used it for years and it worked very well. But (at least in this case)
$r->uri works better (because it works!)

> if that doesn't work we can try another thought pattern :)

It did work, so there's no excuse for getting a new video card :-)

--
#!/usr/bin/perl http://domm.zsi.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

Re: [Semi-OT] mod_rewrite and $r->parsed_uri

am 08.04.2005 21:53:05 von Geoffrey Young

>>I don't think anyone is supposed to (or traditionally does) mess with
>>$r->parsed_uri. it's usually $r->uri and $r->filename.
>
>
> Well, in the mod_perl Cookbook you (or one of your co-authors) mess with
> $r->parsed_uri (eg Recipe 5.3 'Altering the Request URI' page 160ff)

yes... but that example doesn't actually alter r->parsed_uri (in the C
request_rec). it just instantiates a new object based on r->parsed_uri and
locally modifies it for use in a redirection.

by "mess" I meant setting that slot in the C request rec, which I'm not even
sure can be done in mp1, but who knows. it's been 3.5 years since that was
written ;)

>
> I used it for years and it worked very well. But (at least in this case)
> $r->uri works better (because it works!)

always best to use what works best :)

>
>
>>if that doesn't work we can try another thought pattern :)
>
>
> It did work, so there's no excuse for getting a new video card :-)

a friend regularly tells me I need something other than my current 1999
monitor, so maybe that first :)

--Geoff