ryan
03/31/2022, 6:08 PMserver set web.rewrites.config=htdocs/.htaccess
ryan
03/31/2022, 6:12 PMbdw429s
03/31/2022, 6:13 PMbdw429s
03/31/2022, 6:13 PMbdw429s
03/31/2022, 6:13 PMbdw429s
03/31/2022, 6:14 PMserver.json
file.ryan
03/31/2022, 6:14 PMryan
03/31/2022, 6:14 PMserver.json
ryan
03/31/2022, 6:15 PMryan
03/31/2022, 6:15 PMserver.json
I will have to do some research.ryan
03/31/2022, 6:19 PMserver log --follow --rewrites
No log file found for 'F:\code\web\sites\test\'!
f:/code/.CommandBox/server/691EA0275822000979443F2EF19D8A91-test/lucee-5.3.8.206/logs/rewrites.txt
Enable Rewrite logging with [server set web.rewrites.logEnable=true] and ensure you are started in debug mode.
ryan
03/31/2022, 6:22 PMbdw429s
03/31/2022, 6:23 PMryan
03/31/2022, 6:23 PMrestart --debug
bdw429s
03/31/2022, 6:23 PMbdw429s
03/31/2022, 6:23 PMbdw429s
03/31/2022, 6:24 PMryan
03/31/2022, 7:01 PMbdw429s
03/31/2022, 7:03 PMryan
03/31/2022, 7:03 PMbdw429s
03/31/2022, 7:03 PMserver log --rewrites
bdw429s
03/31/2022, 7:04 PMryan
03/31/2022, 7:04 PMryan
03/31/2022, 7:05 PMCommandBox:amalga-ccpb> server log --rewrites
[ERROR] Rewrite utils.ModRewriteConfLoader: Unknown line: AddType 'text/html; charset=UTF-8' html
[ERROR] Rewrite utils.ModRewriteConfLoader: Unknown line: AddType 'text/css; charset=UTF-8' css
[ERROR] Rewrite utils.ModRewriteConfLoader: Unknown line: AddType 'application/javascript; charset=UTF-8' js
[ERROR] Rewrite utils.ModRewriteConfLoader: Unknown line: Options -Indexes
[DEBUG] Rewrite: processing request for /_admin
[DEBUG] Rewrite Output: needs no substitution
[DEBUG] Rewrite: processing request for /_admin
[DEBUG] Rewrite Output: needs no substitution
bdw429s
03/31/2022, 7:06 PMryan
03/31/2022, 7:06 PMryan
03/31/2022, 7:07 PMryan
03/31/2022, 7:07 PMbdw429s
03/31/2022, 7:08 PMbdw429s
03/31/2022, 7:08 PMryan
03/31/2022, 7:08 PMbdw429s
03/31/2022, 7:08 PMryan
03/31/2022, 7:10 PM#
# Everything is UTF-8
#
AddType 'text/html; charset=UTF-8' html
AddType 'text/css; charset=UTF-8' css
#
# - correct way to serve js according to <http://www.ietf.org/rfc/rfc4329.txt>
# - IE doesn't like application/javascript but on the other hand it doesn't
# obey Content-Type headers so it's ok
AddType 'application/javascript; charset=UTF-8' js
# disable directory browsing
Options -Indexes
#
# The order of the rewrite rules is generally important
RewriteEngine On
RewriteBase /
# If we are in the admin area or we already have the language variable skip this block of rules
RewriteCond %{REQUEST_URI} ^/(_admin|_docs|_cfc|assets|images)
RewriteRule .* - [S=6]
#
# The language must be the first thing in the URL. If it's present then set
# and env variable, remove it from the URL and continue with other rules
#
# e.g. en/dir/file.cfm; en/dir1/dir2/file.cfm; en/dir/file.php
RewriteRule ^(en|jp)/(.+/)*(.+)\.(cfm|php) $1/$2$3.$4 [QSA]
# e.g. en/; en/dir/; en/dir1/dir2/
RewriteRule ^(en|jp)/(.+/)*$ $1/$2 [QSA]
# Details for a news, etc: /dir/dir/#fuseaction#/#id#-#name#
RewriteRule ^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)([a-zA-Z0-9\-_\\]+)/(\d+)-?(.*)$ $1/$2index.cfm?fuseaction=$3&id=$4&title=$5 [NC,NS,L,QSA]
# Download asset /dir/dir/download_asset/#name#
RewriteRule ^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)(download_asset)/([^.]+\.\w{3,})-?.*$ $1/$2index.cfm?fuseaction=$3&id=$4 [NC,NS,L,QSA]
# Download asset /dir/dir/products/#type#
RewriteRule ^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)products/(\w+)$ $1/$2index.cfm?fuseaction=product_details&id=$3 [NC,NS,L,QSA]
# Simple fuseaction (/directory/directory/#fuseaction#)
RewriteRule ^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)([a-zA-Z0-9\-_\\]+)$ $1/$2index.cfm?fuseaction=$3 [QSA]
RewriteCond %{REQUEST_URI} ^/(testbed|assets/script/charting_library)
RewriteRule .* - [S=1]
# Ignore revision numbers in JS and CSS file names
RewriteRule ^((?:[a-z0-9\-_\\]+/)*)(\d+)\.(.+)\.(js|css)$ $1$3.$4 [NC,NS,L]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?webtest.*$ [NC]
RewriteRule ^_data/.+$ - [F]
bdw429s
03/31/2022, 7:21 PMRewriteRule .* - [S=1]
I've never seen the skip flag. The rule above skips the next 1 rulebdw429s
03/31/2022, 7:21 PMbdw429s
03/31/2022, 7:21 PMgoto
but even more brittlebdw429s
03/31/2022, 7:21 PMbdw429s
03/31/2022, 7:22 PM# The language must be the first thing in the URL. If it's present then set
# and env variable, remove it from the URL and continue with other rules
• I'm not sure what it means by setting an "env var"
• Despite that comment, all the rules below it seem to still expect a language to be present in the URL
🤔ryan
03/31/2022, 7:23 PMbdw429s
03/31/2022, 7:24 PMbdw429s
03/31/2022, 7:24 PMryan
03/31/2022, 7:25 PMbdw429s
03/31/2022, 7:25 PM# Ignore revision numbers in JS and CSS file names
That's an interesting approach, lol. They get their cache busting in the browser, but keep the file names the same on disk!bdw429s
03/31/2022, 7:26 PMI was thinking somehow that it was grabbing either "en" or "jp" from the url path and then removing and adding it somehow to an environment variable.I know what the comments say. What I'm saying is that's not what the rules is doing!
bdw429s
03/31/2022, 7:27 PMRewriteRule ^(en|jp)/(.+/)*(.+)\.(cfm|php) $1/$2$3.$4 [QSA]
The en
or jp
is presumably capture group 1, whcih is totally being used in the final URL as `$1`'ryan
03/31/2022, 7:27 PMbdw429s
03/31/2022, 7:40 PM# Details for a news, etc: /dir/dir/#fuseaction#/#id#-#name#
RewriteRule ^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)([a-zA-Z0-9\-_\\]+)/(\d+)-?(.*)$ $1/$2index.cfm?fuseaction=$3&id=$4&title=$5 [NC,NS,L,QSA]
ryan
03/31/2022, 7:41 PMbdw429s
03/31/2022, 7:43 PMryan
03/31/2022, 7:43 PMbdw429s
03/31/2022, 7:44 PMryan
03/31/2022, 7:44 PMryan
03/31/2022, 7:44 PMbdw429s
03/31/2022, 7:44 PMryan
03/31/2022, 7:44 PMbdw429s
03/31/2022, 7:45 PMryan
03/31/2022, 7:45 PMbdw429s
03/31/2022, 7:46 PMbdw429s
03/31/2022, 7:46 PMbdw429s
03/31/2022, 7:46 PMryan
03/31/2022, 7:46 PMbdw429s
03/31/2022, 7:46 PMbdw429s
03/31/2022, 7:46 PMryan
03/31/2022, 7:46 PMbdw429s
03/31/2022, 7:46 PMbdw429s
03/31/2022, 7:47 PMregex('(.*).jpg$') -> redirect('${1}.png')
bdw429s
03/31/2022, 7:47 PMryan
03/31/2022, 7:47 PMryan
03/31/2022, 7:48 PMbdw429s
03/31/2022, 7:51 PMregex( case-sensitive=false, pattern='^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)([a-zA-Z0-9\-_\\]+)/(\d+)-?(.*)$') -> { rewrite( '${1}/{$2}index.cfm?fuseaction=${3}&id=${4}&title=${5}' ); last; }
bdw429s
03/31/2022, 7:52 PM${foo}
syntax as CommandBox's JSON files, you have to escape them as \${foo}
as wellbdw429s
03/31/2022, 7:52 PMbdw429s
03/31/2022, 7:52 PMrules.txt
file, then you don't have to escape anything at all, which is niceryan
03/31/2022, 7:54 PMbdw429s
03/31/2022, 7:59 PMbdw429s
03/31/2022, 7:59 PMstart --console --trace
after the site starts, hit enter a few times to tell where the previous logging stops, hit one page you expect to rewrite, and then read through the logs which will include ALL built in rules as wellbdw429s
03/31/2022, 8:00 PMserver set profile=none
will probably help with testing since it will turn off all baked in CommandBox rules to reduce trace outputryan
03/31/2022, 8:00 PMbdw429s
03/31/2022, 8:01 PMryan
03/31/2022, 8:02 PMserver set web.rulesFile=htdocs/rules.txt
ryan
03/31/2022, 8:05 PMryan
03/31/2022, 8:06 PMrestart --console --trace
work just the same?ryan
03/31/2022, 8:09 PMstart --console --trace
[TRACE] Runwar: regex( case-sensitive=false, pattern='^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)([a-zA-Z0-9\-_\\]+)/(\d+)-?(.*)$') -> { rewrite( '${1}/{$2}index.cfm?fuseaction=${3}&id=${4}&title=${5}' ); last; }
[ERROR] java.lang.IllegalArgumentException: UT000045: Error parsing predicated handler string no handler named last known handlers are [disallowed-methods, allowed-methods, buffer-request, jdbc-access-log, http-continue-accept, secure-cookie, access-log, mark-secure, response-rate-limit, canonical-path, response-code, disable-cache, ssl-headers, trace, block-external, blocking, url-decoding, block-cf-admin, error-file, access-control, redirect, set, ip-access-control, samesite-cookie, request-limit, resource, compress, restart, clear, byte-range, eager-form-parser, set-error, done, rewrite, forwarded, stuck-thread-detector, reverse-proxy, jvm-route, learning-push, dump-request, proxy-peer-address, resolve-local-name, header, store-response, path-separator, uncompress, resolve-peer-name]:
regex( case-sensitive=false, pattern='^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)([a-zA-Z0-9\-_\\]+)/(\d+)-?(.*)$') -> { rewrite( '${1}/{$2}index.cfm?fuseaction=${3}&id=${4}&title=${5}' ); last; }
^
[ERROR] at io.undertow.server.handlers.builder.PredicatedHandlersParser.error(PredicatedHandlersParser.java:729)
[ERROR] at io.undertow.server.handlers.builder.PredicatedHandlersParser.handleHandlerNode(PredicatedHandlersParser.java:157)
[ERROR] at io.undertow.server.handlers.builder.PredicatedHandlersParser.handleNode(PredicatedHandlersParser.java:114)
[ERROR] at io.undertow.server.handlers.builder.PredicatedHandlersParser.handleBlockNode(PredicatedHandlersParser.java:147)
[ERROR] at io.undertow.server.handlers.builder.PredicatedHandlersParser.handlePredicatedAction(PredicatedHandlersParser.java:137)
[ERROR] at io.undertow.server.handlers.builder.PredicatedHandlersParser.handlePredicateOperatorNode(PredicatedHandlersParser.java:125)
[ERROR] at io.undertow.server.handlers.builder.PredicatedHandlersParser.handleNode(PredicatedHandlersParser.java:117)
[ERROR] at io.undertow.server.handlers.builder.PredicatedHandlersParser.parse(PredicatedHandlersParser.java:91)
[ERROR] at runwar.Server.startServer(Server.java:668)
[ERROR] at runwar.Start.main(Start.java:50)
[DEBUG] Runwar: Running shutdown hook
[DEBUG] Runwar: shutdown hook:stopServer()
[INFO ] Runwar: ******************************************************************************
[INFO ] Runwar: *** stopping server 'amalga-ccpb' (socket 63639)
[INFO ] Runwar: ******************************************************************************
[DEBUG] Runwar: All deployments undeployed and underlying Undertow servers stopped
[TRACE] Runwar: Unhooking system streams logger
[DEBUG] Runwar: Stopped server
[DEBUG] Runwar: shutdown hook joining main thread
[DEBUG] Runwar: Shutdown hook finished
Server's output stream closed. It's been stopped elsewhere.
Stopping server...
bdw429s
03/31/2022, 8:09 PMNo, because the restart command only accepts a few params, and console and trace aren't among them 🙂work just the same?restart --console --trace
restart ?
bdw429s
03/31/2022, 8:11 PMreceived an errThere's a syntax error in the rule. What have you done to try and find it? 🙂
bdw429s
03/31/2022, 8:11 PMbdw429s
03/31/2022, 8:11 PM{}
and the last;
bits from the ruleryan
03/31/2022, 8:11 PMbdw429s
03/31/2022, 8:12 PMregex( case-sensitive=false, pattern='^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)([a-zA-Z0-9\-_\\]+)/(\d+)-?(.*)$') -> rewrite( '${1}/{$2}index.cfm?fuseaction=${3}&id=${4}&title=${5}' )
ryan
03/31/2022, 8:21 PMryan
03/31/2022, 8:23 PMryan
03/31/2022, 8:23 PMryan
03/31/2022, 8:23 PMbdw429s
03/31/2022, 8:28 PMbdw429s
03/31/2022, 8:28 PMbdw429s
03/31/2022, 8:28 PMryan
03/31/2022, 8:29 PMryan
03/31/2022, 8:30 PMbdw429s
03/31/2022, 8:39 PMryan
03/31/2022, 8:39 PMbdw429s
03/31/2022, 8:39 PMryan
03/31/2022, 8:40 PMryan
03/31/2022, 8:42 PM;
but it erroredryan
03/31/2022, 8:42 PM[TRACE] Runwar: regex( case-sensitive=false, pattern='^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)([a-zA-Z0-9\-_\\]+)/(\d+)-?(.*)$') -> { rewrite( '${1}/{$2}index.cfm?fuseaction=${3}&id=${4}&title=${5}' ); last }
[ERROR] java.lang.IllegalArgumentException: UT000045: Error parsing predicated handler string no handler named last known handlers are [disallowed-methods, allowed-methods, buffer-request, jdbc-access-log, http-continue-accept, secure-cookie, access-log, mark-secure, response-rate-limit, canonical-path, response-code, disable-cache, ssl-headers, trace, block-external, blocking, url-decoding, block-cf-admin, error-file, access-control, redirect, set, ip-access-control, samesite-cookie, request-limit, resource, compress, restart, clear, byte-range, eager-form-parser, set-error, done, rewrite, forwarded, stuck-thread-detector, reverse-proxy, jvm-route, learning-push, dump-request, proxy-peer-address, resolve-local-name, header, store-response, path-separator, uncompress, resolve-peer-name]:
regex( case-sensitive=false, pattern='^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)([a-zA-Z0-9\-_\\]+)/(\d+)-?(.*)$') -> { rewrite( '${1}/{$2}index.cfm?fuseaction=${3}&id=${4}&title=${5}' ); last }
bdw429s
03/31/2022, 8:44 PMbdw429s
03/31/2022, 8:46 PMdone
not last
lolbdw429s
03/31/2022, 8:46 PMbdw429s
03/31/2022, 8:46 PMbdw429s
03/31/2022, 8:46 PMregex('/\.') and not path-prefix(.well-known) -> { set-error( 404 ); done }
ryan
03/31/2022, 8:47 PMryan
03/31/2022, 8:52 PM[ERROR] Mar 31, 2022 4:48:21 PM javax.mail.Session loadResource
WARNING: expected resource not found: /META-INF/javamail.default.address.map
ryan
03/31/2022, 8:57 PMbdw429s
03/31/2022, 9:03 PMbdw429s
03/31/2022, 9:03 PMryan
03/31/2022, 9:18 PMRewriteCond %{REQUEST_URI} ^/(_admin|_docs|_cfc|assets|images)
RewriteRule .* - [S=6]
bdw429s
03/31/2022, 9:19 PMbdw429s
03/31/2022, 9:20 PMbdw429s
03/31/2022, 9:21 PMbdw429s
03/31/2022, 9:21 PMbdw429s
03/31/2022, 9:22 PMdone
bdw429s
03/31/2022, 9:22 PMbdw429s
03/31/2022, 9:47 PMequals( foo, foo) -> {
equals( foo, foo) -> rewrite( /foo );
equals( foo, bar) -> rewrite( /bar );
equals( foo, baz) -> rewrite( /baz );
} else {
set(attribute='%{o,css}', value='false');
path(/whee) -> response-code( 404 );
}
bdw429s
03/31/2022, 9:52 PMnot regex( case-sensitive=false, pattern='^/(_admin|_docs|_cfc|assets|images)' ) -> {
regex( case-sensitive=false, pattern='^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)([a-zA-Z0-9\-_\\]+)/(\d+)-?(.*)$') -> {
rewrite( '${1}/{$2}index.cfm?fuseaction=${3}&id=${4}&title=${5}' );
done;
}
regex( case-sensitive=false, pattern='^another pattern') -> {
rewrite( 'another rewrite' );
done;
}
}
bdw429s
03/31/2022, 9:53 PMryan
03/31/2022, 9:54 PMryan
03/31/2022, 9:54 PMbdw429s
03/31/2022, 9:54 PMryan
03/31/2022, 9:55 PMbdw429s
03/31/2022, 9:55 PMbdw429s
03/31/2022, 9:55 PMbdw429s
03/31/2022, 9:55 PM{}
, but I had never tried nesting more predicatesryan
03/31/2022, 9:57 PMryan
03/31/2022, 10:06 PMbdw429s
03/31/2022, 10:13 PMbdw429s
03/31/2022, 10:14 PM❯ cat server.json
{
"profile":"none",
"web":{
"rulesFile":"rules.txt"
}
}
bdw429s
03/31/2022, 10:14 PMryan
04/01/2022, 12:29 PMand
in the predicate as two regex statements in one predicate. It stopped erroring and seems to work, but not sure yet, because the website is still not coming to life with these rules in place, which leads me to believe that the forward slashes may have something to do with this issue.ryan
04/01/2022, 1:45 PMryan
04/01/2022, 1:46 PMryan
04/01/2022, 4:25 PMbdw429s
04/01/2022, 4:36 PMbdw429s
04/01/2022, 4:37 PMbdw429s
04/01/2022, 4:37 PM/
) in regex so there's no need to escape anything therebdw429s
04/01/2022, 4:37 PMbdw429s
04/01/2022, 4:40 PMwhat's the point of nesting one predicate? Maybe I can use anJust brevity. Why doin the predicate as two regex statements in one predicateand
if( condition1 && conditionA ) {
} else if( condition1 && conditionB ) {
} else if( condition1 && conditionC ) {
} else if( condition1 && conditionD ) {
}
when you can do
if( condition1 ) {
if( conditionA ) {
} else if( conditionB ) {
} else if( conditionC ) {
} else if( conditionD ) {
}
}
That's not too hard to read, but consider
• conditionA is likely much more characters in real life
• If you change conditionA, you've got to edit 4 placesbdw429s
04/01/2022, 4:42 PMthe website is still not coming to life with these rules in place, which leads me to believe that the forward slashes may have something to do with this issue.Quit worrying about what you think the issue may be and figure out what the actual issue is 🙂 So for a given page that's not working • which specific rule should be kicking in • how is that rule supposed to work • what about the rule isn't working like it needs to? • Fix it Bullets 1 and 2 are up to you, bullet three should be evident from the trace console logs that show what the rules are doing.
ryan
04/01/2022, 5:00 PMryan
04/01/2022, 5:07 PMnot regex( case-sensitive=false, pattern='^/(_admin|_docs|_cfc|assets|images)' ) -> {
regex( case-sensitive=false, pattern='^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)([a-zA-Z0-9\-_\\]+)/(\d+)-?(.*)$') -> {
rewrite( '${1}/{$2}index.cfm?fuseaction=${3}&id=${4}&title=${5}%q' );
done;
}
regex( case-sensitive=false, pattern='^(en|jp)/(.+/)*(.+)\.(cfm|php)') -> {
rewrite( '$1/$2$3.$4%q' );
done;
}
regex( case-sensitive=false, pattern='^(en|jp)/(.+/)*$') -> {
rewrite( '$1/$2%q' );
done;
}
regex( case-sensitive=false, pattern='^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)(download_asset)/([^.]+\.\w{3,})-?.*$') -> {
rewrite( '$1/$2index.cfm?fuseaction=$3&id=$4%q' );
done;
}
regex( case-sensitive=false, pattern='^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)products/(\w+)$') -> {
rewrite( '$1/$2index.cfm?fuseaction=product_details&id=$3%q' );
done;
}
regex( case-sensitive=false, pattern='^(en|jp)/((?:[a-zA-Z0-9\-_\\]+/)*)([a-zA-Z0-9\-_\\]+)$') -> {
rewrite( '$1/$2index.cfm?fuseaction=$3%q' );
done;
}
}
not regex( case-sensitive=false, pattern='^/(testbed|assets/script/charting_library)' ) and regex( case-sensitive=false, pattern='^((?:[a-z0-9\-_\\]+/)*)(\d+)\.(.+)\.(js|css)$' ) -> {
rewrite( '$1$3.$4%q' );
done;
}
regex( case-sensitive=false, pattern='!^http(s)?://(www\.)?ccpb.*$') -> {
rewrite('^_data/.+$%q');
done;
}
ryan
04/01/2022, 5:08 PMryan
04/01/2022, 5:09 PMbdw429s
04/01/2022, 5:20 PMbdw429s
04/01/2022, 5:20 PMryan
04/01/2022, 5:21 PMryan
04/01/2022, 5:21 PMryan
04/03/2022, 4:52 PMbdw429s
04/03/2022, 8:57 PMbdw429s
04/03/2022, 8:58 PMrewrite( '$1/$2?fuseaction=$3' );
and not
rewrite( '${1}/${2}?fuseaction=${3}' );
Can you confirm that syntax works? I was thinking about this the other day since I was thinking I had seen that before, but when I looked through the official undertow docs again I couldn't find any references to it so I wasn't sure.bdw429s
04/03/2022, 9:00 PM$1
does for sure work instead of ${1}
I'd like to change the rest of my examples over to use that since it doesn't need to be escaped as \${1}
in the server.json
ryan
04/05/2022, 1:22 PMryan
04/05/2022, 1:24 PM${n}
.
2. I cannot get the following to work for some reason. It is supposed to remove the numbers from the file, but it does not.
Server Rules: Regex pattern [^((?:[a-z0-9\-_\\]+/)*)(\d+)\.(.+)\.(js|css)$] DOES NOT MATCH input [/assets/style/dist/529250.style.css] for HttpServerExchange{ GET /assets/style/dist/529250.style.css}.
Server Rules: Predicate [regex( pattern='^((?:[a-z0-9\-_\\]+/)*)(\d+)\.(.+)\.(js|css)$', value='%{RELATIVE_PATH}', full-match='false', case-sensitive='true' )] resolved to false for HttpServerExchange{ GET /assets/style/dist/529250.style.css}.
ryan
04/05/2022, 1:54 PM^(
like ^(/(?:[a-z0-9\-_\\]+/)*)(\d+)\.(.+)\.(js|css)$
It finally rewrote and the css is showing up now that it is pointed to an existing file with the numbers in the filename.
Now the original rules line with the 2 predicates works!
Server Rules: Predicate [ not regex( pattern='^/(testbed|assets/script/charting_library)', value='%{RELATIVE_PATH}', full-match='false', case-sensitive='true' ) and regex( pattern='^(/(?:[a-z0-9\-_\\]+/)*)(\d+)\.(.+)\.(js|css)$', value='%{RELATIVE_PATH}', full-match='false', case-sensitive='true' )] resolved to true. Next handler is [PredicatesHandler with 2 predicates] for HttpServerExchange{ GET /assets/style/dist/529250.style.css}.
ryan
04/05/2022, 2:33 PMlucee-[version]\.predicateFile.txt
This helped me determine if I could place comments in the rules.txt file and after Undertow processes the rules.txt file, the output is saved into the .predicateFile.txt. #
is the comment line character.ryan
04/05/2022, 2:40 PM[DEBUG] io.undertow.request.error-response: Setting error code 500 for exchange HttpServerExchange{ GET /}
java.lang.RuntimeException: null
at io.undertow.server.HttpServerExchange.setStatusCode(HttpServerExchange.java:1484) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.spec.HttpServletResponseImpl.setStatus(HttpServletResponseImpl.java:287) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at javax.servlet.http.HttpServletResponseWrapper.setStatus(HttpServletResponseWrapper.java:192) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at lucee.runtime.PageContextImpl.handlePageException(PageContextImpl.java:2022) [5.3.8.206.lco:?]
at lucee.runtime.util.PageContextUtil.getHandlePageException(PageContextUtil.java:227) [5.3.8.206.lco:?]
at lucee.runtime.exp.CatchBlockImpl.castToString(CatchBlockImpl.java:225) [5.3.8.206.lco:?]
at lucee.runtime.op.Decision.isString(Decision.java:965) [5.3.8.206.lco:?]
at lucee.runtime.op.Decision.isCastableToString(Decision.java:977) [5.3.8.206.lco:?]
at lucee.runtime.op.Decision.isCastableTo(Decision.java:1339) [5.3.8.206.lco:?]
at lucee.runtime.type.UDFImpl.castToAndClone(UDFImpl.java:112) [5.3.8.206.lco:?]
at lucee.runtime.type.UDFImpl.defineArguments(UDFImpl.java:164) [5.3.8.206.lco:?]
at lucee.runtime.type.UDFImpl._call(UDFImpl.java:342) [5.3.8.206.lco:?]
at lucee.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:207) [5.3.8.206.lco:?]
at lucee.runtime.ComponentImpl._call(ComponentImpl.java:685) [5.3.8.206.lco:?]
at lucee.runtime.ComponentImpl._call(ComponentImpl.java:572) [5.3.8.206.lco:?]
at lucee.runtime.ComponentImpl.callWithNamedValues(ComponentImpl.java:1930) [5.3.8.206.lco:?]
at lucee.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:866) [5.3.8.206.lco:?]
at lucee.runtime.PageContextImpl.getFunctionWithNamedValues(PageContextImpl.java:1766) [5.3.8.206.lco:?]
at db_migrate_cfm$cf.call(/db_migrate.cfm:127) [?:?]
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1034) [5.3.8.206.lco:?]
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:926) [5.3.8.206.lco:?]
at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:907) [5.3.8.206.lco:?]
at application_cfc$cf.udfCall(/Application.cfc:24) [?:?]
at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:106) [5.3.8.206.lco:?]
at lucee.runtime.type.UDFImpl._call(UDFImpl.java:344) [5.3.8.206.lco:?]
at lucee.runtime.type.UDFImpl.call(UDFImpl.java:217) [5.3.8.206.lco:?]
at lucee.runtime.ComponentImpl._call(ComponentImpl.java:684) [5.3.8.206.lco:?]
at lucee.runtime.ComponentImpl._call(ComponentImpl.java:572) [5.3.8.206.lco:?]
at lucee.runtime.ComponentImpl.call(ComponentImpl.java:1911) [5.3.8.206.lco:?]
at lucee.runtime.listener.ModernAppListener.call(ModernAppListener.java:437) [5.3.8.206.lco:?]
at lucee.runtime.listener.ModernAppListener.onApplicationStart(ModernAppListener.java:304) [5.3.8.206.lco:?]
at lucee.runtime.PageContextImpl.initApplicationContext(PageContextImpl.java:3135) [5.3.8.206.lco:?]
at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:120) [5.3.8.206.lco:?]
at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:44) [5.3.8.206.lco:?]
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2460) [5.3.8.206.lco:?]
at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2450) [5.3.8.206.lco:?]
at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2421) [5.3.8.206.lco:?]
at lucee.runtime.engine.Request.exe(Request.java:45) [5.3.8.206.lco:?]
at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1179) [5.3.8.206.lco:?]
at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1125) [5.3.8.206.lco:?]
at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97) [lucee.jar:?]
at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51) [lucee.jar:?]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:590) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at org.cfmlprojects.regexpathinfofilter.RegexPathInfoFilter.doFilter(RegexPathInfoFilter.java:47) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:405) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:280) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:79) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:134) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:131) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:260) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:79) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:100) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:387) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:852) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2019) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1558) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1423) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1280) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
at java.lang.Thread.run(Unknown Source) [?:?]
bdw429s
04/05/2022, 6:19 PMIt works with a forward slash added after@ryan yeah, that's one annoying difference between web servers is whether you're request URL always comes in with the leading slash.
foo
vs /foo
I'm guessing Apache was a little different there.ryan
04/05/2022, 6:20 PMbdw429s
04/05/2022, 6:22 PMjava.lang.RuntimeException: null
at io.undertow.server.HttpServerExchange.setStatusCode(HttpServerExchange.java:1484) [runwar-4.7.2-SNAPSHOT.jar:4.7.2-SNAPSHOT]
Hmm, that one is really odd. It doesn't seem to be related at all to your rewrites. You have CF code in /db_migrate.cfm
which has thrown an exception, and as part of that, Lucee is setting the reponse's status code to 500. But some sort of error has happened inside of Undertow while setting that. I can't say I've ever seen this before.bdw429s
04/05/2022, 6:22 PMbdw429s
04/05/2022, 6:23 PMbdw429s
04/05/2022, 6:23 PMbdw429s
04/05/2022, 6:23 PMbdw429s
04/05/2022, 6:23 PMif(statusCode >= 500) {
if(UndertowLogger.ERROR_RESPONSE.isDebugEnabled()) {
UndertowLogger.ERROR_RESPONSE.debugf(new RuntimeException(), "Setting error code %s for exchange %s", statusCode, this);
}
}
bdw429s
04/05/2022, 6:24 PMbdw429s
04/05/2022, 6:24 PMbdw429s
04/05/2022, 6:24 PMtrace
level debugging in the server start
?bdw429s
04/05/2022, 6:24 PMryan
04/05/2022, 6:24 PMbdw429s
04/05/2022, 6:25 PMryan
04/05/2022, 6:25 PMbdw429s
04/05/2022, 6:25 PMbdw429s
04/05/2022, 6:25 PMryan
04/05/2022, 6:25 PMryan
04/05/2022, 6:25 PMbdw429s
04/05/2022, 6:25 PMbdw429s
04/05/2022, 6:27 PMbdw429s
04/05/2022, 6:27 PMbdw429s
04/05/2022, 6:27 PMryan
04/05/2022, 6:28 PMbdw429s
04/05/2022, 6:28 PMbdw429s
04/05/2022, 6:28 PMbdw429s
04/05/2022, 6:28 PMryan
04/05/2022, 6:28 PMryan
04/05/2022, 6:29 PMbdw429s
04/05/2022, 6:29 PMryan
04/05/2022, 6:29 PMbdw429s
04/05/2022, 6:29 PMbdw429s
04/05/2022, 6:29 PMryan
04/05/2022, 6:30 PMbdw429s
04/05/2022, 6:30 PMryan
04/05/2022, 6:30 PMryan
04/05/2022, 6:31 PMryan
04/05/2022, 8:25 PM${HTTP_REFERER}
would be for UnderTow?ryan
04/05/2022, 8:26 PMryan
04/05/2022, 8:27 PMryan
04/05/2022, 8:31 PM%{REQUEST_URI}
equivalent. However, I do not see a way to change it.
regex( case-sensitive=false, pattern='!^http(s)?://(www\.)?ccpb.*$') -> {
rewrite('^/_data/.+$');
done;
}
bdw429s
04/06/2022, 2:33 PMI was looking at exchange attributes for UnderTow, but I believe those are for the handler and not the predicates@ryan untrue. exchange attributes can be used anywhere. They are just a generic abstraction around any parts of the HTTP request or response you want to get or set.
bdw429s
04/06/2022, 2:33 PMryan
04/06/2022, 2:34 PMbdw429s
04/06/2022, 2:34 PM%{i,request_header_name} - Any request header
bdw429s
04/06/2022, 2:34 PM%{i,HTTP_REFERER}
bdw429s
04/06/2022, 2:34 PMi
stands for "incoming" so it's a request headerbdw429s
04/06/2022, 2:35 PM%{o,response_header_name} - Any response headerwhere the
o
stands for "outgoing" which are response headersbdw429s
04/06/2022, 2:35 PMI think the regex refers to the ApacheCorrect, unless you provide a specific exchange attribute for your regex to be applied to, it will look at the request URIequivalent.%{REQUEST_URI}
ryan
04/06/2022, 2:35 PMregex( case-sensitive=false, pattern='!^http(s)?://(www\.)?ccpb.*$', value="%h", full-match=true)
, but I think I may have to remove case-sensitive=false
I have to test it more today.bdw429s
04/06/2022, 2:35 PMbdw429s
04/06/2022, 2:36 PMregex(pattern="Googlebot", value="%{i,USER-AGENT}", case-sensitive=false ) -> set-error( 404 )
which looks at the user agent headerbdw429s
04/06/2022, 2:36 PM%h
is the "Remote host name". is that what you want?bdw429s
04/06/2022, 2:37 PMbdw429s
04/06/2022, 2:37 PMbdw429s
04/06/2022, 2:37 PM%h
https://undertow.io/undertow-docs/undertow-docs-2.0.0/#built-in-handlers-2
It has all the exchange attributes listed that Undertow supportsbdw429s
04/06/2022, 2:38 PMvalue="%{i,HTTP_REFERER}"
ryan
04/06/2022, 2:38 PMbdw429s
04/06/2022, 2:39 PMI think the regex with a value will allow for the exchange attributeI don't understand what you mean by that
bdw429s
04/06/2022, 2:39 PMbdw429s
04/06/2022, 2:39 PMryan
04/06/2022, 2:40 PMbdw429s
04/06/2022, 2:40 PMbdw429s
04/06/2022, 2:41 PMbdw429s
04/06/2022, 2:41 PM%HTTP_REFERRER
as a shortcut for %{i,HTTP_REFERER}
, you can write a small Java class, drop it in the classpath, and it will get sucked in and added to the languagebdw429s
04/06/2022, 2:42 PMbdw429s
04/06/2022, 2:42 PMbdw429s
04/06/2022, 2:42 PMcf-admin()
and handlers such as block-external()
are my own creations and only exist if using undertow inside of CommandBoxryan
04/06/2022, 2:43 PMryan
04/06/2022, 2:43 PMbdw429s
04/06/2022, 2:44 PMdo-rewrites()
and the that will be all you have in your predicate file 😆ryan
04/06/2022, 2:45 PMbdw429s
04/06/2022, 2:50 PMbdw429s
04/06/2022, 2:51 PMbdw429s
04/06/2022, 2:51 PMweb.config
file, but in my experience IIS useres rarely ever use thatryan
04/06/2022, 4:04 PMbdw429s
04/06/2022, 4:15 PMbdw429s
04/06/2022, 4:16 PM{}
) , all it takes is for a developer to add or remove a line and break the entire flowbdw429s
04/06/2022, 4:16 PMryan
04/07/2022, 6:06 PM