Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

[OT] Re: modifying the query string & uri without a redirect ?

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


john-modperl at o-rourke

Dec 24, 2005, 6:10 AM

Post #1 of 2 (479 views)
Permalink
[OT] Re: modifying the query string & uri without a redirect ?

I'll give you the mod_rewrite solution but a mod_perl handler version is
similarly simple.

RewriteRule /user/(.+)(/profile)? /user/profile?id=$1 [NS]

This creates an internal subrequest (ie. users don't see it) for the new
URI, and if I remember rightly mod_rewrite will sort out your query
string for you. If you have collisions with the 'id' parameter I'd
suggest changing your program logic - HTTP doesn't strongly define
parameter ordering or precedence so you might get unexpected results!

mod_rewrite only does an external redirect (so users see it) if the
destination URI is absolute (http://...) or if you add the 'R' flag
(like this: "..... ?id=$1 [R,NS]" )

$preferred_term_of_merriment $choice_of_religious_holiday,
John

Jonathan Vanasco wrote:

> Currently a page is accessed like this:
> /user/profile?id=X
>
> I'm trying to get url schemes like this to map to that page
> /users/X
> /users/X/profile
>
> I tried doing it in mod_rewrite. there i ran into 2 problems:
> a_ the new mapping is shown to the user
> b_ i can either replace the query string entirely, or append the
> new 'id' to it. if there's an existing id param in the string
> though, i run into a collison


modperl-list at 2xlp

Dec 24, 2005, 10:33 AM

Post #2 of 2 (440 views)
Permalink
Re: [OT] Re: modifying the query string & uri without a redirect ? [In reply to]

(OT)

Ah. Very odd.

I misinterpreted the NS flag

I had:
RewriteRule ^/users/([\d]{1,9})$ /users/?id=$1 [QSA,L]

Now I have
RewriteRule ^/users/([\d]{1,9})(/)?$ /users/?id=$1 [QSA,NS,L]

And it all works fine.

I realized that I wasn't seeing an actual redirect, but the query
string was appeneded into the browser location.
With the NS, flag, the query string will not show. I'm not sure why
that happens or how. Maybe its in part because I'm running this on
localhost.

festive festivus,
Jonathan




On Dec 24, 2005, at 9:10 AM, John ORourke wrote:

> I'll give you the mod_rewrite solution but a mod_perl handler
> version is similarly simple.
>
> RewriteRule /user/(.+)(/profile)? /user/profile?id=$1 [NS]
>
> This creates an internal subrequest (ie. users don't see it) for
> the new URI, and if I remember rightly mod_rewrite will sort out
> your query string for you. If you have collisions with the 'id'
> parameter I'd suggest changing your program logic - HTTP doesn't
> strongly define parameter ordering or precedence so you might get
> unexpected results!
>
> mod_rewrite only does an external redirect (so users see it) if the
> destination URI is absolute (http://...) or if you add the 'R' flag
> (like this: "..... ?id=$1 [R,NS]" )
>
> $preferred_term_of_merriment $choice_of_religious_holiday,
> John

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.