diff --git a/lib/file.c b/lib/file.c
index 9421c445b0e0ea0d41f49ca8fdb9dfc0d2b9d703..4447c73f6852281153af001b2e413b5bc89f5f15 100644
--- a/lib/file.c
+++ b/lib/file.c
@@ -119,7 +119,7 @@ const struct Curl_handler Curl_handler_file = {
   ZERO_NULL,                            /* readwrite */
   0,                                    /* defport */
   CURLPROTO_FILE,                       /* protocol */
-  PROTOPT_NONETWORK                     /* flags */
+  PROTOPT_NONETWORK | PROTOPT_NOURLQUERY /* flags */
 };
 
 
diff --git a/lib/url.c b/lib/url.c
index 4bc82a65fa7f73f278439623f0769de724d50185..aa64bccafced37db36090a09d8c094526925e868 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -4823,6 +4823,25 @@ static CURLcode create_conn(struct SessionHandle *data,
   if(result != CURLE_OK)
     return result;
 
+
+  /*************************************************************
+   * If the protocol can't handle url query strings, then cut
+   * of the unhandable part
+   *************************************************************/
+  if((conn->given->flags&PROTOPT_NOURLQUERY)) {
+    char *path_q_sep = strchr(conn->data->state.path, '?');
+    if(path_q_sep) {
+      /* according to rfc3986, allow the query (?foo=bar)
+         also on protocols that can't handle it.
+
+        cut the string-part after '?'
+         */
+
+      /* terminate the string */
+      path_q_sep[0] = 0;
+    }
+  }
+
 #ifndef CURL_DISABLE_PROXY
   /*************************************************************
    * Extract the user and password from the authentication string
diff --git a/lib/urldata.h b/lib/urldata.h
index 3e7db2525c9f0b5ae57e78c2159c19356bcaa0cf..55f0a7b851ae5d41aeb3cfa92671c7e4f50acf76 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -713,6 +713,8 @@ struct Curl_handler {
 #define PROTOPT_NONETWORK (1<<4)   /* protocol doesn't use the network! */
 #define PROTOPT_NEEDSPWD (1<<5)    /* needs a password, and if none is set it
                                       gets a default */
+#define PROTOPT_NOURLQUERY (1<<6)   /* protocol can't handle
+                                        url query strings (?foo=bar) ! */
 
 
 /* return the count of bytes sent, or -1 on error */
diff --git a/tests/data/test219 b/tests/data/test219
new file mode 100644
index 0000000000000000000000000000000000000000..28566595a5f98ada986e6e7d3bf87133a415dbdb
--- /dev/null
+++ b/tests/data/test219
@@ -0,0 +1,30 @@
+<testcase>
+# Server-side
+<reply>
+<data>
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+file
+</server>
+ <name>
+file:// URLs with query string
+ </name>
+ <command>
+file://localhost/%PWD/log/test202.txt?a_query=foobar#afragment
+</command>
+<file name="log/test202.txt">
+contents in a single file
+</file>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<stdout>
+contents in a single file
+</stdout>
+</verify>
+</testcase>

