homepage Welcome to WebmasterWorld Guest from 54.198.140.148
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Can you Rewrite a URL part to the QueryString?
spinnercee




msg:3257007
 5:21 pm on Feb 19, 2007 (gmt 0)

If I have something like:

/path/base_abc_def_ghi.gif
/path/base_jkl_mno_pqr.gif

Can I rewrite that to become CGI script options like this:

/CGIscriptpath/script?option=abc_def_ghi
/CGIscriptpath/script?option=jkl_mno_pqr

I would want to use the /path/base_ to trigger the rewrite and take everything after that, excluding the .gif to become the querystring's "option" value.

In my mind it seems pretty simple --- In code, I'd just extract the substring from the source URL and append it to the target URL.

I'm also wondering if a redirect has to be sent or if the source URL can just be mapped to the target internally without ReWriting? (both the source and target are local to the same HTTPd).

Or, would a simple redirect work?

Redirect /path/base_ /CGIscriptpath/script?option=
or RedirectMatch perhaps?

* can a same-server redirect target start with a "/" (a local absolute URL) or does it need to start with http:...? ie:

Redirect /path/base_ http://example.com/CGIscriptpath/script?option=

In this case, my script would then have to strip the .gif from the querystring, but that's ok.

 

jdMorgan




msg:3257090
 6:38 pm on Feb 19, 2007 (gmt 0)

See Apache mod_rewrite [httpd.apache.org], especially the term "back-reference" in the RewriteRule and RewriteCond directive descriptions.

Jim

spinnercee




msg:3258353
 12:39 am on Feb 21, 2007 (gmt 0)

Here's what I did for now, instead of:

/path/base_abc.def.ghi.gif

I create URLs like:

/path/base/abc.def.ghi.gif

in httpd.conf, I have

Redirect /path/base/ http://example.com/CGIscriptpath/script?option=

This allows what looks like a URL to actually be script input. PHP explode()s the option into different vars.

For now this is OK -- now I'll get to the rewriting action... Thanks of pointing me in the right direction.

jdMorgan




msg:3258425
 1:47 am on Feb 21, 2007 (gmt 0)

The problem with the "Redirect" solution is that, well, it's an external redirect, thus exposing the script URL to the search engines...

You can use mod_rewrite to rewrite --not redirect-- the request, in order to avoid that problem.

Alternately, you could use AcceptPathInfo [httpd.apache.org] to pass parameters from the URL to your script.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved