revised question

14 views
Skip to first unread message

whostheJBoss

unread,
Jun 25, 2009, 2:49:46 PM6/25/09
to UrlRewrite
I hope this is more clear.


With this URL:

http://www.mysite.com/ms/create/?debugmode=true&debugpass=password

How can I write a rule that will match and rewrite it to:

http://www.mysite.com/index.php?PATH_INFO=ms/create/&debugmode=true&debugpass=password

-------------
-------------

I want to make sure that any of the following URLS would do the same:

http://www.mysite.com/ms/create?debugmode=true&debugpass=password

To:

http://www.mysite.com/index.php?PATH_INFO=ms/create/&debugmode=true&debugpass=password


I have these next ones working, they are last in the rule list, so I
really just need the first two figured out, so that they will fire
before the chain reaches these next two.

THIS: ----

http://www.mysite.com/?debugmode=true&debugpass=password

To:

http://www.mysite.com/index.php?PATH_INFO=&debugmode=true&debugpass=password

----
AND:
----

http://www.mysite.com/?debugmode=true&debugpass=password

To:

http://www.mysite.com/index.php?PATH_INFO=&debugmode=true&debugpass=password


Basically, I need anything that has a query string (a question mark, ?
=this=that or ?whatever=something&more=less) to redirect to:

http://www.mysite.com/index.php passing anything before the ? as
PATH_INFO and anything after as ?=variable=value&variable2=value2, etc

The following rule achieves the first two examples I need:

<rule>
<from>^/\?(.*)$</from>
<to last="true">/index.cfm?$1</to>
<set name="urlrewrite.originalRequestUri">%{request-uri}</set>
<set name="urlrewrite.originalQueryString">%{query-string}</set>
</rule>

(the set elements are not necessary, they are just there for me to use
later)

However, trying this rule will not match the last two I need, such as
whatever/whatever/?something=value

<rule>
<from>^/\?(.*)$</from>
<to last="true">/index.cfm?$1&amp;match=1</to>
<set name="urlrewrite.originalRequestUri">%{request-uri}</set>
<set name="urlrewrite.originalQueryString">%{query-string}</set>
</rule>

It ends up matching something like this:

http://www.mysite.com/ms/create/?debugmode=true&debugpass=password

To this rule:

<rule>
<from>^/(.*)$</from>
<to last="true">/index.cfm?PATH_INFO=$1&amp;match=2</to>
<set name="urlrewrite.originalRequestUri">%{request-uri}</set>
<set name="urlrewrite.originalQueryString">%{query-string}</set>
</rule>

And redirecting to:

http://www.mysite.com/index.php?PATH_INFO=ms/create/?debugmode=true&debugpass=password

Instead of:

http://www.mysite.com/index.php?PATH_INFO=ms/create/&debugmode=true&debugpass=password

It matches everything from /ms... on, including the ? as $1

I can add this:

&amp;%{query-string}to the end of this line:

<to last="true">/index.cfm?PATH_INFO=$1&amp;match=2&amp;%{query-
string}</to>

Then I can get the query original query string, but the PATH_INFO
contains the wrong information, it has the info I need PLUS the extra
query string information. With the query string added to the end, it
attempts to go to this URL:

http://www.mysite.com/index.php?PATH_INFO=ms/create/?debugmode=true&debugpass=password&debugmode=true&debugpass=true

So, since there is a ? in the PATH_INFO variable, it treats that as
part of the variable, but the & breaks the variable and starts a new
one with debugpass. The problem is that the appended query string also
contains debugpass, so I end up with the value
debugpass=password,password not debugpass=password

So, I need a way to match everything before the ? as PATH_INFO so that
I can append the query string without getting a duplicate.

How can I match everything before ? as PATH_INFO and everything
after ? as the query string?

Thanks! I have been tearing my hair out over this!

Avlesh Singh

unread,
Jun 26, 2009, 12:29:21 AM6/26/09
to urlre...@googlegroups.com
Solution to your problem:
Try this -
Have two rules in your rewrite config as underneath

<rule>
  <from>^/(.*)\?(.*)$</from>
  <to>/index.cfm?$1&amp;$2</to>
</rule>

<rule>
  <from>^/(.*)$</from>
  <to>/index.cfm?$1</to>
</rule>

The first one would handle all your url's with a queryString. The second one you obviously know.

Afterthoughts:
This kind of a need fits into something known as a QueryStringAppend (QSA) flag in Apache's mod_rewrite. There is no corresponding support in our lovely UrlRewrite filter as of now. I created an issue for the same here - http://code.google.com/p/urlrewritefilter/issues/detail?id=31#c1
If this support were present then your rule could have been as simple as the underneath and the rewrite filter should have done all the heavy lifting for you.

<rule qsa="true">
  <from>^/(.*)$</from>
  <to>/index.cfm?$1</to>
</rule>

I am proposing this as a solution for the issue mentioned above.
Thoughts?

Cheers
Avlesh

whostheJBoss

unread,
Jun 26, 2009, 8:04:46 AM6/26/09
to UrlRewrite
Thanks!

The following seems to have accomplished what I need:

<rule>

<from>^/\?(.*)$</from>

<to last="true">/index.cfm?$1</to>

<set name="urlrewrite.originalRequestUri">%{request-uri}</set>

<set name="urlrewrite.originalQueryString">%{query-string}</set>

</rule>



<rule>

<from>^/(.*)$/\?(.*)</from>

<to last="true">/index.cfm?PATH_INFO=$1&amp;%{query-string}</to>

<set name="urlrewrite.originalRequestUri">%{request-uri}</set>

<set name="urlrewrite.originalQueryString">%{query-string}</set>

</rule>





<rule>

<from>^/(.*)$</from>

<to last="true">/index.cfm?PATH_INFO=$1&amp;%{query-string}</to>

<set name="urlrewrite.originalRequestUri">%{request-uri}</set>

<set name="urlrewrite.originalQueryString">%{query-string}</set>

</rule>

On Jun 25, 9:29 pm, Avlesh Singh <avl...@gmail.com> wrote:
> *Solution to your problem:
> *Try this -
> Have two rules in your rewrite config as underneath
>
> <rule>
>   <from>^/(.*)\?(.*)$</from>
>   <to>/index.cfm?$1&amp;$2</to>
> </rule>
>
> <rule>
>   <from>^/(.*)$</from>
>   <to>/index.cfm?$1</to>
> </rule>
>
> The first one would handle all your url's with a queryString. The second one
> you obviously know.
>
> *Afterthoughts:
> *This kind of a need fits into something known as a QueryStringAppend (QSA)
> flag in Apache's mod_rewrite. There is no corresponding support in our
> lovely UrlRewrite filter as of now. I created an issue for the same here -http://code.google.com/p/urlrewritefilter/issues/detail?id=31#c1
> If this support were present then your rule could have been as simple as the
> underneath and the rewrite filter should have done all the heavy lifting for
> you.
>
> <rule qsa="true">
>   <from>^/(.*)$</from>
>   <to>/index.cfm?$1</to>
> </rule>
>
> I am proposing this as a solution for the issue mentioned above.
> Thoughts?
>
> Cheers
> Avlesh
>
> On Fri, Jun 26, 2009 at 12:19 AM, whostheJBoss
> <dotfus...@changethings.org>wrote:
>
>
>
> > I hope this is more clear.
>
> > With this URL:
>
> >http://www.mysite.com/ms/create/?debugmode=true&debugpass=password
>
> > How can I write a rule that will match and rewrite it to:
>
> >http://www.mysite.com/index.php?PATH_INFO=ms/create/&debugmode=true&d...
>
> > -------------
> > -------------
>
> > I want to make sure that any of the following URLS would do the same:
>
> >http://www.mysite.com/ms/create?debugmode=true&debugpass=password
>
> > To:
>
> >http://www.mysite.com/index.php?PATH_INFO=ms/create/&debugmode=true&d...
>
> > I have these next ones working, they are last in the rule list, so I
> > really just need the first two figured out, so that they will fire
> > before the chain reaches these next two.
>
> > THIS: ----
>
> >http://www.mysite.com/?debugmode=true&debugpass=password
>
> > To:
>
> >http://www.mysite.com/index.php?PATH_INFO=&debugmode=true&debugpass=p...
>
> > ----
> > AND:
> > ----
>
> >http://www.mysite.com/?debugmode=true&debugpass=password
>
> > To:
>
> >http://www.mysite.com/index.php?PATH_INFO=&debugmode=true&debugpass=p...
>
> > Basically, I need anything that has a query string (a question mark, ?
> > =this=that or ?whatever=something&more=less) to redirect to:
>
> >http://www.mysite.com/index.phppassing anything before the ? as
> >http://www.mysite.com/index.php?PATH_INFO=ms/create/?debugmode=true&d...
>
> > Instead of:
>
> >http://www.mysite.com/index.php?PATH_INFO=ms/create/&debugmode=true&d...
>
> > It matches everything from /ms... on, including the ? as $1
>
> > I can add this:
>
> > &amp;%{query-string}to the end of this line:
>
> >  <to last="true">/index.cfm?PATH_INFO=$1&amp;match=2&amp;%{query-
> > string}</to>
>
> > Then I can get the query original query string, but the PATH_INFO
> > contains the wrong information, it has the info I need PLUS the extra
> > query string information. With the query string added to the end, it
> > attempts to go to this URL:
>
> >http://www.mysite.com/index.php?PATH_INFO=ms/create/?debugmode=true&d...

Avlesh Singh

unread,
Jun 26, 2009, 9:51:44 PM6/26/09
to urlre...@googlegroups.com
Awesome! I can understand why the suggested rules expanded from 2 to 3. :)
If you think it is worth doing, the please vote for the issue - http://code.google.com/p/urlrewritefilter/issues/detail?id=31

Cheers
Avlesh
Reply all
Reply to author
Forward
0 new messages