Alessandro Lia
07/19/2023, 4:53 PM<rule name="api" stopProcessing="true">
<match url="api/(v[1-9]+)/(.+.*)$" ignoreCase="true" />
<conditions>
<add input="{PATH_INFO}" pattern="^.*/index.cfm.*$" negate="true" />
</conditions>
<action type="Rewrite" url="core/framework/api/{R:1}/index.cfm?endpoint=/{R:2}" />
</rule>
I tried with this customRewrites.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN" "<http://tuckey.org/res/dtds/urlrewrite4.0.dtd>">
<urlrewrite use-query-string="true">
<rule>
<name>Api redirect</name>
<from>^api/(v[1-9]+)/(.+.*)$</from>
<condition type="request-url" operator="notequal">/index\.cfm.*$</condition>
<to>core/framework/api/$1/index.cfm?endpoint=/$2</to>
</rule>
</urlrewrite>
I also tried removing the ^
inside from
tag, but doesn't work (I'm gettin' 404)
Also, in my server.json I do this
"web":{
...
"rewrites":{
"enable":true,
"config":"customRewrites.xml",
"logEnable":true,
"statusPath":"/rewriteStatus",
"configReloadSeconds":"30"
},
But if I navigate https://site/rewriteStatus I always get a 404.
Any help really appreciated!bdw429s
07/19/2023, 4:53 PMexample
here
Alessandro Lia
07/19/2023, 4:55 PMbdw429s
07/19/2023, 4:56 PMbdw429s
07/19/2023, 4:58 PMThis is what I need: https://site/api/v1/xxx must be rewritten to https://site/core/framework/api/v1/xxxbut your actual rewrite looks different
<action type="Rewrite" url="core/framework/api/{R:1}/index.cfm?endpoint=/{R:2}" />
It seems you are adding an index.cfm
in there?Alessandro Lia
07/19/2023, 4:58 PMAlessandro Lia
07/19/2023, 4:58 PMbdw429s
07/19/2023, 4:58 PMbdw429s
07/19/2023, 4:58 PMAlessandro Lia
07/19/2023, 4:59 PMbdw429s
07/19/2023, 5:00 PM<add input="{PATH_INFO}" pattern="^.*/index.cfm.*$" negate="true" />
But are there existing valid URLs which start with
/api/vN/
which should not be rewritten?bdw429s
07/19/2023, 5:00 PMAlessandro Lia
07/19/2023, 5:03 PMbdw429s
07/19/2023, 5:03 PM(.+.*)
That's a capture group containing 1 or more character, followed by 0 or more characters, but that's redundant. You should just be able to move the .*
entirely.Alessandro Lia
07/19/2023, 5:04 PMbdw429s
07/19/2023, 5:04 PMyes if you don't use that pattern, it will be an infinite replaceThat's only because your regex is wrong 🙂 Anchor it to the start of the string with
^
and it will work without the conditionAlessandro Lia
07/19/2023, 5:05 PMbdw429s
07/19/2023, 5:05 PMapi/(v[1-9]+)/(.+.*)$
will match anywhere in the string, but
^api/(v[1-9]+)/(.+.*)$
will only match at the start of the stringbdw429s
07/19/2023, 5:05 PMapi/(v[1-9]+)/(.+.*)$
is the functional equivalent of
.*api/(v[1-9]+)/(.+.*)$
bdw429s
07/19/2023, 5:07 PM[1-9]+
are you planning on skipping v10
and going straight from v9
to v11
? 🙂Alessandro Lia
07/19/2023, 5:08 PMAlessandro Lia
07/19/2023, 5:09 PMAlessandro Lia
07/19/2023, 5:09 PMbdw429s
07/19/2023, 5:11 PMAlessandro Lia
07/19/2023, 5:13 PMbdw429s
07/19/2023, 5:13 PMgoto sandbox
mkdir rewritetest --cd
server set web.rules[1]="regex-nocase( '^/api/(v[0-9]+)/(.*)$' ) -> rewrite( '/core/framework/api/\\\${1}/index.cfm?endpoint=\\\${2}' )"
touch core/framework/api/v1/index.cfm
start --console --trace
bdw429s
07/19/2023, 5:14 PM<http://127.0.0.1:51720/api/v1/foobar>
in my browserbdw429s
07/19/2023, 5:14 PM[DEBUG] Runwar: requested: '<http://127.0.0.1:51720/api/v1/foobar>'
[TRACE] Server Rules: Regex pattern [^/api/(v[0-9]+)/(.*)$] MATCHES input [/api/v1/foobar] for HttpServerExchange{ GET /api/v1/foobar}.
[TRACE] Server Rules: Storing regex match group [0] as [/api/v1/foobar] for HttpServerExchange{ GET /api/v1/foobar}.
[TRACE] Server Rules: Storing regex match group [1] as [v1] for HttpServerExchange{ GET /api/v1/foobar}.
[TRACE] Server Rules: Storing regex match group [2] as [foobar] for HttpServerExchange{ GET /api/v1/foobar}.
[TRACE] Server Rules: Predicate [regex( pattern='^/api/(v[0-9]+)/(.*)$', value='%{RELATIVE_PATH}', full-match='false', case-sensitive='true' )] resolved to true. Next handler is [rewrite( 'NDA' )] for HttpServerExchange{ GET /api/v1/foobar}.
[DEBUG] Server Rules: Request rewritten to [/core/framework/api/v1/index.cfm?endpoint=foobar] for HttpServerExchange{ GET /api/v1/foobar}.
Alessandro Lia
07/19/2023, 5:17 PMAlessandro Lia
07/19/2023, 5:18 PMbdw429s
07/19/2023, 5:29 PMserver.json
{
"web": {
"rules": [
"regex-nocase( '^/api/(v[0-9]+)/(.*)$' ) -> rewrite( '/core/framework/api/\\${1}/index.cfm?endpoint=\\${2}' )"
]
}
}
aliaspooryorik
They will be deprecated in the next release
aliaspooryorik
Alessandro Lia
07/20/2023, 3:17 PM"rules":[
"regex-nocase( '^/api/(v[0-9]+)/(.*)$' ) -> rewrite( '/core/framework/api/\\${1}/index.cfm?endpoint=/\\${2}' )"
]
while debugging I see that I need to redirect to /apiname
and not just apiname
, or Taffy will fail.
Also, talking about IIS, after some tries I remember why we need to set the matcher to api/(v[1-9]+)/(.+.*)$
without the initial caret: IIS will not match the rule if you add the first caret, so you need to drop it and add the index.cfm
exceptionAlessandro Lia
07/20/2023, 3:17 PMbdw429s
07/20/2023, 3:29 PMbdw429s
07/20/2023, 3:29 PM^/api
not ^api
bdw429s
07/20/2023, 3:30 PMaliaspooryorik
aliaspooryorik
bdw429s
07/20/2023, 4:19 PM