I have a very simple Node.js blog system running on OpenShift. When it reads metadata for a blog entry, it saves the title after passing it through encodeURIComponent
. That percent-encoded string is then used as the post "key" in the URL.
For example:
- I write a blog post, titled "post/with/slashes"
- My blogging system reads the title from the metadata, and saves the blog post udner "post%2Fwith%2Fslahes"
- My loving readers go to
my-blog.io/post/post%2Fwith%2Fslahes
in their web browsers
I'm using Express, and first of all I noticed that Express decodes the URL string before passing to my app (that is, my code finds the string "post/with/slashes"
in the request parameters). So I pass it through encodeURIComponent again before looking up the post. I don't think that's relevant, but I've mentioned it just in case.
My problem: When I run a local instance (this is "standalone" Node.js, no Apache going on), this works fine. Express passes me "post/with/slashes"
, I pass that string through encodeURIComponent
and I look up the post. But when I deploy to OpenShift, the request does not reach my app at all. I am served OpenShift's default 404 page, which says "The requested URL /post/post/with/slashes was not found on this server."
In summary: it looks like Apache is decoding the percent-encoded URL before passing it to Node.js. Since there are now slashes in the URL, Express doesn't know how to route the request to my app. Is this expected (and if so why)? If not, why might it be happening and what could I do about it?