|
Mailing Lists
|
Home /
Groups /
Regular Expressions (RegEx)
ISAPI Converting URL value
I was wondering is anyone could help, Using Regex how do I go about converting e.g. http://127.0.0.1/imp/www/index.cfm?id=889 to http://127.0.0.1/imp/www/889.cfmAbigail Coker 08/04/08 10:13 A > Using Regex how do I go about converting e.g.Peter Boughton 08/04/08 10:23 A >I'm not sure about the specifics of ISAPI Rewrite, but these should do whatAbigail Coker 08/04/08 10:29 A >I'm not sure about the specifics of ISAPI Rewrite, but these should do whatAbigail Coker 08/04/08 12:05 P > Going by your example I tried the code below it threw an error but I stuckPeter Boughton 08/04/08 12:15 P Thanks a lot Peter, both worked like a dream.Abigail Coker 08/04/08 12:25 P I was wondering is anyone could help, Using Regex how do I go about converting e.g. http://127.0.0.1/imp/www/index.cfm?id=889 to http://127.0.0.1/imp/www/889.cfm The value 889 can be any number... Thanks Abigail > Using Regex how do I go about converting e.g. > http://127.0.0.1/imp/www/index.cfm?id=889 to > http://127.0.0.1/imp/www/889.cfm > > The value 889 can be any number... > I'm not sure about the specifics of ISAPI Rewrite, but these should do what you want... Match: ([^?#]*/imp/www)/(\d+).cfm Replace: \1/index.cfm?id=\2 (Might need $1 and $2 instead of \1 and \2 in replace) ----- Excess quoted text cut - see Original Post for more ----- Thanks Peter, I'll try it. ----- Excess quoted text cut - see Original Post for more ----- Going by your example I tried the code below it threw an error but I stuck an extra # but doesn't seem to do anything....I've tried a some workarounds with joy. <cfset stringToWork = Rereplace("http://127.0.0.1/imp/www/index.cfm?id=889","([^?#]*/imp/www)/(\d+).cfm","\1/index.cfm?id=\2","ALL")> <cfoutput>#stringToWork#</cfoutput> This is what I had http://127.0.0.1/imp/www/index.cfm?id=889 ----- Excess quoted text cut - see Original Post for more ----- Ah, what I had given you will work the other way round - converting from 889.cfm to index.cfm?id=889 Just to be clear, here are a couple of working examples for both directions... <cfset input = "http://127.0.0.1/imp/www/index.cfm?id=889"/> <cfset output = rereplace( input , "([^?##]*/imp/www)/index.cfm\?id=(\d+)" , "\1/\2.cfm" )/> <cfoutput>#input# -> #output#</cfoutput> <hr/> <cfset input = "http://127.0.0.1/imp/www/889.cfm"/> <cfset output = rereplace( input , "([^?##]*/imp/www)/(\d+).cfm" , "\1/index.cfm?id=\2" )/> <cfoutput>#input# -> #output#</cfoutput> Thanks a lot Peter, both worked like a dream. Thanks, Abi HI abigail, i'm not sure, but i think you have this backwards. isapi_rewrite takes the incoming url & converts it to a physical url _before_ iis/cf/php etc gets ahold of it. my guess is that you really want to convert: http://127.0.0.1/imp/www/889 (note the lack of a ".cfm" which is not needed when doing this config) to: http://127.0.0.1/imp/www/index.cfm?id=889 the easiest way to do this is to simply anchor to the back of the string using the $ and look for numeric values using [0-9]+ so the regex would simply look like this: /([0-9]*)$/ then in the parsed output you would just do something like this: index.cfm?id=\1 all of your output code will just need to have the urls formatted to use the new 'clean' system. Hope this helps! -Chris Hi Chris, Thanks for your input, the 2 examples Peter gave actually worked, just out of interest I'll try your example and see what I get. Thanks, Abi -----------------------------------------------------------------------------------
|
May 24, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||