Help with Rewrite Rule!

View: New views
7 Messages — Rating Filter:   Alert me  

Help with Rewrite Rule!

by cf coder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello everybody,

I'm struggling to get my rewrite rule to work. I would appreciate any help I can get.

I'll try to explain as best as I can.

I want a RewriteRule that can do the following:

I have a rule that translates:

http://mysite/index.cfm?offers.books&bookid=1

to:

http://mysite/offers/books/Harry-Potter

I have a mapfile.txt file in helicon my rewriteengine.

And a rule that does this is:
RewriteRule /offers(/books/.*) /index.cfm?go=offers.details&bookid=${mapfile:$1}

The mapfile.txt file contains the "book keyword url" and "bookid",
ex: /books/Harry-Potter  1

and a rule that translates: http://mysite/index.cfm?go=books.all

to:

http://mysite/offers/books/all

And the rule that does this is:
RewriteRule /offers/books/([a-zA-Z0-9.-]+)(.*) /index.cfm?go=offers\.$1 [PT]

Here's the problem: When I try to browse this page: "http://mysite/offers/books/all" the browser gets confused because the regular expression pattern for both the rules have the same pattern i.e "/offers/books/". I hope this is making sense. I want to change my rule which works in both the cases.

Rules:

RewriteRule /offers/books/([a-zA-Z0-9.-]+)(.*) /index.cfm?go=offers\.$1 [PT]
RewriteRule /offers(/books/.*) /index.cfm?go=offers.details&bookid=${mapfile:$1}

I can browse this page (it's working): http://mysite/offers/books/all

but when I try to browse this page: http://mysite/offers/books/Harry-Potter

I get an error which states: This is the template "../fuseboxShared/ErrorTemplates/fusebox.undefinedFuseaction.cfm" An Error of type "fusebox.undefinedFuseaction" has occurred undefined Fuseaction You specified a Fuseaction of Harry-Potter which is not defined in Circuit books.

This is what I have in the httpd.conf file:

RewriteEngine on
RewriteMap mapfile txt:mapfile.txt

RewriteRule /offers/books/([a-zA-Z0-9.-]+)(.*) /index.cfm?go=offers\.$1
RewriteRule /offers(/books/.*) /index.cfm?go=offers.details&bookid=${mapfile:$1}

The first rule is getting executed when I try to browse: http://mysite/offers/books/Harry-Potter

It errors because the text "/offers/books/" is in both the rules but only want the first rule to execute when the "bookid" doesn't exist in the url.

Any ideas to get around this problem?


Thanks in advance.

Regards,

cfcoder

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w

Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1121
Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21


Re: Help with Rewrite Rule!

by Ben Doom-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The way you've got this written, you'll never get to your second rule.
There is no way in the regex directly to tell you if there was a mapfile
match.

There might be a way to do it with the rewrite API, but I'm not really
familiar with it.

What I would do is change the URL for the offers to something other than
/books/
You could simply add something static like
/books/offers/
which would allow you to specify additional static text in your regex,
or you could change it altogether to something like
/offers/

HTH

--Ben Doom

cf coder wrote:

> Hello everybody,
>
> I'm struggling to get my rewrite rule to work. I would appreciate any help I can get.
>
> I'll try to explain as best as I can.
>
> I want a RewriteRule that can do the following:
>
> I have a rule that translates:
>
> http://mysite/index.cfm?offers.books&bookid=1
>
> to:
>
> http://mysite/offers/books/Harry-Potter
>
> I have a mapfile.txt file in helicon my rewriteengine.
>
> And a rule that does this is:
> RewriteRule /offers(/books/.*) /index.cfm?go=offers.details&bookid=${mapfile:$1}
>
> The mapfile.txt file contains the "book keyword url" and "bookid",
> ex: /books/Harry-Potter  1
>
> and a rule that translates: http://mysite/index.cfm?go=books.all
>
> to:
>
> http://mysite/offers/books/all
>
> And the rule that does this is:
> RewriteRule /offers/books/([a-zA-Z0-9.-]+)(.*) /index.cfm?go=offers\.$1 [PT]
>
> Here's the problem: When I try to browse this page: "http://mysite/offers/books/all" the browser gets confused because the regular expression pattern for both the rules have the same pattern i.e "/offers/books/". I hope this is making sense. I want to change my rule which works in both the cases.
>
> Rules:
>
> RewriteRule /offers/books/([a-zA-Z0-9.-]+)(.*) /index.cfm?go=offers\.$1 [PT]
> RewriteRule /offers(/books/.*) /index.cfm?go=offers.details&bookid=${mapfile:$1}
>
> I can browse this page (it's working): http://mysite/offers/books/all
>
> but when I try to browse this page: http://mysite/offers/books/Harry-Potter
>
> I get an error which states: This is the template "../fuseboxShared/ErrorTemplates/fusebox.undefinedFuseaction.cfm" An Error of type "fusebox.undefinedFuseaction" has occurred undefined Fuseaction You specified a Fuseaction of Harry-Potter which is not defined in Circuit books.
>
> This is what I have in the httpd.conf file:
>
> RewriteEngine on
> RewriteMap mapfile txt:mapfile.txt
>
> RewriteRule /offers/books/([a-zA-Z0-9.-]+)(.*) /index.cfm?go=offers\.$1
> RewriteRule /offers(/books/.*) /index.cfm?go=offers.details&bookid=${mapfile:$1}
>
> The first rule is getting executed when I try to browse: http://mysite/offers/books/Harry-Potter
>
> It errors because the text "/offers/books/" is in both the rules but only want the first rule to execute when the "bookid" doesn't exist in the url.
>
> Any ideas to get around this problem?
>
>
> Thanks in advance.
>
> Regards,
>
> cfcoder
>
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w

Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1122
Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21


Re: Help with Rewrite Rule!

by cf coder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I beleive the ISAPI_Rewrite directive RewriteCond can do the trick but I can't get it tow work either.

The incoming url has the 'bookid' url parameter and so I want to add the cond before the rule

RewriteCond? The condition should say, "if there is a bookid query parameter" run this rule:

RewriteCond %{QUERY_STRING} bookid
RewriteRule /offers(/books/.*) /index.cfm?go=offers.details&bookid=${mapfile:$1}

The above doesn't work. Any ideas or suggestions?

Regards,
cfcoder

>The way you've got this written, you'll never get to your second rule.
>There is no way in the regex directly to tell you if there was a mapfile
>match.
>
>There might be a way to do it with the rewrite API, but I'm not really
>familiar with it.
>
>What I would do is change the URL for the offers to something other than
>/books/
>You could simply add something static like
>/books/offers/
>which would allow you to specify additional static text in your regex,
>or you could change it altogether to something like
>/offers/
>
>HTH
>
>--Ben Doom
>
>cf coder wrote:
>>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w

Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1123
Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21


Re: Help with Rewrite Rule!

by Ben Doom-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

cf coder wrote:
> RewriteCond %{QUERY_STRING} bookid

Your incoming URL doesn't have a bookid in it -- that's what you are
rewriting to.  One or more of us is confused.  It could very well be me.
  :-)

Also, if you use (/books/.*) then the match that is (I guess) looked up
in your mapfile will include the books keyword, eg. /books/harry-potter
instead of just what follows it.

--Ben Doom


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w

Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1124
Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21


Re: Help with Rewrite Rule!

by cf coder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm the one who's confused :) The rule: RewriteRule /offers(/books/.*) /index.cfm?go=offers.details&bookid=${mapfile:$1} creates the dynamic link ex: http://mysite/offers/books/Harry-Potter and so I was thinking maybe I could add a RewriteCond directive before this rule?


>cf coder wrote:
>> RewriteCond %{QUERY_STRING} bookid
>
>Your incoming URL doesn't have a bookid in it -- that's what you are
>rewriting to.  One or more of us is confused.  It could very well be me.
>  :-)
>
>Also, if you use (/books/.*) then the match that is (I guess) looked up
>in your mapfile will include the books keyword, eg. /books/harry-potter
>instead of just what follows it.
>
>--Ben Doom

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w

Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1125
Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21


Re: Help with Rewrite Rule!

by Ben Doom-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I thought the problem was with incoming links, not creating outgoing
links.  Was I wrong about that?

--Ben Doom

cf coder wrote:

> I'm the one who's confused :) The rule: RewriteRule /offers(/books/.*) /index.cfm?go=offers.details&bookid=${mapfile:$1} creates the dynamic link ex: http://mysite/offers/books/Harry-Potter and so I was thinking maybe I could add a RewriteCond directive before this rule?
>
>
>> cf coder wrote:
>>> RewriteCond %{QUERY_STRING} bookid
>> Your incoming URL doesn't have a bookid in it -- that's what you are
>> rewriting to.  One or more of us is confused.  It could very well be me.
>>  :-)
>>
>> Also, if you use (/books/.*) then the match that is (I guess) looked up
>> in your mapfile will include the books keyword, eg. /books/harry-potter
>> instead of just what follows it.
>>
>> --Ben Doom
>
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w

Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1126
Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user837.14401.21


Re: Help with Rewrite Rule!

by Ben Doom-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Did you ever get this worked out?

--Ben Doom

cf coder wrote:

> I'm the one who's confused :) The rule: RewriteRule /offers(/books/.*) /index.cfm?go=offers.details&bookid=${mapfile:$1} creates the dynamic link ex: http://mysite/offers/books/Harry-Potter and so I was thinking maybe I could add a RewriteCond directive before this rule?
>
>
>> cf coder wrote:
>>> RewriteCond %{QUERY_STRING} bookid
>> Your incoming URL doesn't have a bookid in it -- that's what you are
>> rewriting to.  One or more of us is confused.  It could very well be me.
>>  :-)
>>
>> Also, if you use (/books/.*) then the match that is (I guess) looked up
>> in your mapfile will include the books keyword, eg. /books/harry-potter
>> instead of just what follows it.
>>
>> --Ben Doom
>
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w

Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:1127
Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.21