Welcome to WebmasterWorld Guest from 54.144.68.27

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Can you Rewrite a URL part to the QueryString?

     

spinnercee

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

10+ Year Member



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

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

Jim

spinnercee

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

10+ Year Member



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

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month