cfmlprojects / runwar

Other
11 stars 16 forks source link

Standard HTACCESS rules error #104

Closed gpickin closed 6 years ago

gpickin commented 6 years ago

I have been trying to get some rewrites working with HTACCESS file through commandbox.

I read here: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html And https://cdn.rawgit.com/paultuckey/urlrewritefilter/master/src/doc/manual/4.0/index.html

I am not sure how I can get this working.

Rewrites seem to have no issues, its the REWRITECOND line that errors.

2018-03-09 12:19:50 INFO io.undertow.servlet org.tuckey.web.filters.urlrewrite.Condition ERROR: Condition 0 had error: you must set a name for a header 2018-03-09 12:19:50 INFO io.undertow.servlet org.tuckey.web.filters.urlrewrite.Condition DEBUG: loaded condition header null .(bmp|gif|jpe?g|png|css|js|txt|xls|ico|swf)$ 2018-03-09 12:19:50 INFO io.undertow.servlet org.tuckey.web.filters.urlrewrite.RuleBase DEBUG: failed to load rule 2018-03-09 12:19:50 INFO io.undertow.servlet org.tuckey.web.filters.urlrewrite.NormalRule DEBUG: failed to load rule

My rewrite was as simple as this to start

The ColdBox index.cfm/{path_info} rules.

RewriteRule ^$ index.cfm [QSA,NS] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.cfm%{REQUEST_URI} [QSA,L]

I realized that it should be request-uri instead of request_uri. The only way to get any rewritecond to work was the following

RewriteCond %{HTTP_HOST} !^www.google.com

So... obviously there are a lot of limits... and no good way to know what works and what doesn't work. How do we do this?

bdw429s commented 6 years ago

@denuno Based on the error messages:

header null 

Do you think that %{REQUEST_FILENAME} isn't resolving at all inside Runwar? Does Runwar need to do something to set a header so REQUEST_FILENAME is accessible by Tuckey?

gpickin commented 6 years ago

Using request-uri it doesn't show null, but it will said condition 0 had error: you must set a name for a header

denuno commented 6 years ago

RewriteRule ^(.*)$ index.cfm %{REQUEST_URI}/$1 [QSA,L]

I think you want something like:

RewriteRule ^$ index.cfm [QSA,NS]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.cfm/$1 [QSA,L]

As for debugging, this is a Tuckey UrlRewriteFilter thing, basically, so you'd need to troubleshoot that code, but I think if you enable debug you'd get most the information you need.

After a little digging on my own, you should be able to use %{request-uri} in the "to", but there's an incorrect regex in tuckey that prevents it from working. We're already using a forked version, I'm temped to make your original version work if it's valid... can you verify that the same config really works in apache?

denuno commented 6 years ago

I went ahead and tweaked the fork of UrlRewriteFilter (I don't see a PR into tuckey for the last bit of changes, which might explain why they never got merged), so that you can use the same names in "to" and "from" instead of having to remember to change the case, replace the underscore, etc. -- so the original example should work now (I'm gonna assume it is valid in Apache since a quick online test said it was).

gpickin commented 6 years ago

The conditions are what dont work, with most of the INPUTs that i tried. Hopefully your tweaks work.

This will be a huge help. Way better than resorting to XML :)

denuno commented 6 years ago

Hmmm, when I looked at the debug output, the conditions were parsed fine, it was confused about finding a condition variable in a rule, basically.

Here's what I saw for 3.7.0 with that config:

DEBUG: Rule 1 run called with /funkitron DEBUG: matched "from" DEBUG: fileName found is /workspace/runwar/tests/resource/war/simple.war/funkitron DEBUG: checking to see if /workspace/runwar/tests/resource/war/simple.war/funkitron is not a file DEBUG: fileName found is /workspace/runwar/tests/resource/war/simple.war/funkitron DEBUG: checking to see if /workspace/runwar/tests/resource/war/simple.war/funkitron is not a directory DEBUG: conditions match DEBUG: needs to be forwarded to index.cfm%{REQUEST_URI}

And it actually worked when I used request-uri in the rule, so I'm thinking maybe you're including a different version of UrlRewriteFilter that's getting picked up...

In retrospect, the UrlRewriteFilter classes should probably be renamed when they're shaded in to avoid any potential conflicts, I'll add doing that to The List.

gpickin commented 6 years ago

Did some debugging with Brad today. I'll file new issues for remaining issues. Its much better than it was. Thanks.

samdaams commented 4 years ago

Did you guys ever figure out the cause of this issue, because I am running into EXACTLY this issue. Removing the conditions (same as above) that are kicking back the following error: "urlrewrite.Condition: Condition 0 had error: you must set a name for a header" are trigger, the .htaccess loads fine. With them in there, the whole file ends up being ignored: "urlrewrite.UrlRewriteFilter: Conf failed to load". I'm smacking my head at the wall trying to get this to work. Apache 2.4 (original was 2.2).