cfmlprojects / runwar

Other
11 stars 16 forks source link

How to account for context path in rewrites #136

Open bdw429s opened 6 years ago

bdw429s commented 6 years ago

I was testing starting up a server with the default CommandBox URL rewrites and a custom context path and found it doesn't work which isn't super surprising, but I'm not sure how to fix it.

If I run these commands:

echo "test" > index.cfm
touch includes/test.txt
touch Application.cfm
server set runwar.args="--context-path=/myContext"
start

Then, these URLs work fine:

However, if I enable rewrites:

server set web.rewrites.enable=true
restart --debug

Then this URL still works:

But these URLs don't work:

The error for both of those URLs is a Lucee 404:

Page /myContext/index.cfm [C:\sandbox\contexttest\myContext\index.cfm] not found

It's looking for a physical folder called myContext which doesn't exist. I see this in the debug output which implies that it's getting rewritten:

[DEBUG] urlrewrite.RuleExecutionOutput: needs to be forwarded to /index.cfm/index.cfm
and
[DEBUG] urlrewrite.RuleExecutionOutput: needs to be forwarded to /index.cfm/includes/test.txt

So this sort of makes sense that the Rewrites aren't going to find these paths as real physical paths since the context path is in there, but I'm not clear on whether I need to adjust the rewrite rules or whether this is a bug in Runwar, or Tuckey that's not accounting for a servlet context path.

denuno commented 6 years ago

Hmm, maybe check this out: https://stackoverflow.com/questions/23665573/tuckey-urlrewrite-matching-and-context

Specifically the use-context and %{context-path} bits. The docs seem to say the context will be added automatically, but also maybe that they won't, so... ¯_(ツ)_/¯

bdw429s commented 6 years ago

I'll have to give that a test. If it works, perhaps Runwar can set that automatically for sites with a context. This is fairly edge case. Only 1 person I know of who's tried to use a context.