Can I merge params as one in rewrite handlers or VHOST ?
In example:
{
"from": "/:db/:year/:doc",
"to": "../../../:db%2F:year/:doc",
"method": "GET"
}
I have database named mydb/2015. In URL slash '/' will be URL-encoded to %2F. I would like to have pretty URL and query:
/mydb%2F2015/myDocId
change to
/mydb/2015/myDocId
DocId could have chars which should be URL-encoded.
I'm afraid this is not permitted:
You can have / as part of the document ID but if you refer to a
document in a URL you must always encode it as %2F. One special case
is _design/ documents, those accept either / or %2F for the / after
_design, although / is preferred and %2F is still needed for the rest of the DocID.
Prooflink
Related
I want to create a query parameter without escaping the query string.
For example, I need to create a query parameter q with the content
"before:{2019-12-24 19:57:34}"
so that the URL is
https://android-review.googlesource.com/changes/?q=before:{2019-12-24 19:57:34}
If I use this code (Golang Playground)
url, _ := url.Parse("https://android-review.googlesource.com/changes/")
q := url.Query()
q.Set("q", "before:{2019-12-24 19:57:34}")
url.RawQuery = q.Encode()
fmt.Println(url)
url is escaping the special characters, spaces, and brackets:
https://android-review.googlesource.com/changes/?q=before%3A%7B2019-12-24+19%3A57%3A34%7D
How can I solve this issue except manually creating the URL (without query parameters then)?
If you don't want your URL query to be encoded, then don't use the Encode() method. Instead, set the RawQuery value directly, yourself:
url, _ := url.Parse("https://android-review.googlesource.com/changes/")
url.RawQuery = "q=before:{2019-12-24 19:57:34}"
fmt.Println(url)
Output:
https://android-review.googlesource.com/changes/?q=before:{2019-12-24 19:57:34}
playground
Keep in mind, however, that this is a recipe for potential disaster, depending on how that url is eventually used. In particular, the space in that URL should be escaped, according to RFC. See more here.
Perhaps you'll want to implement your own minimal escaping, if that's compatible with your use-case.
I’d like to know if it’s possible to use header casing for GraphQL field names, like that:
type Headers {
Accept: String
Content-Type: String
}
I have tried this way, with simple quotes, double quotes and backticks : neither of these works.
Any idea ?
GraphQL names can contain ASCII letters, digits, and underscores only, and can't begin with digits. There's no way to declare or consume fields that don't match this rule. You just can't have a field named Content-Type.
It seems conventional for field names to start with lowercase letters, but this isn't required. Accept is a valid field name, but a more typical API would use camelCase naming
type Headers {
accept: String
contentType: String
}
I have the following mod_rewrite code for lighttpd, but it does not properly foreward the user:
$SERVER["socket"] == ":3041" {
server.document-root = server_root + "/paste"
url.rewrite-once = ( "^/([^/\.]+)/?$" => "?page=paste&id=$1")
}
It should turn the url domain.com/H839jec into domain.com/index.php?page=paste&id=H839jec however it is not doing that, instead it is redirecting everything to domain.com. I dont know much about mod_rewrite and would appreciate some input on why it is doing this.
Use the following :
url.rewrite-once = ("^/(.*)$" => "/?page=paste&id=$1")
I don't know the exact issue in your code, but first the regex looks unnecessarily complicated and may not match what you expected it to match, and second you're redirecting to a query string where as I would expect you still need to redirect to a valid path before the query string, that's why I redirect to /?page... instead of just ?page....
I have a script that makes an ajax request passing 3 different data : eventName / ticketsToWin / totalWinners.
My whole process was working perfectly until I had this case : "SCi+Tec" as the eventName variable. Here is what looks like the data of the request just before sending :
name=Sci+Tec&ticketsToWin=1&totalWinners=2
But then, on the PHP side, if I dump the _GET array, I have this :
array(4) {
["name"]=> string(7) "Sci Tec"
["ticketsToWin"]=> string(1) "1"
["totalWinners"]=> string(1) "2"
["_"]=> string(13) "1372359516001"
}
The '+' character is missing in the name, which breaks everything that comes after. Any idea why ?!
Thans!
encode your string:
name=Sci%2BTec&ticketsToWin=1&totalWinners=2
Or easier:
var str = 'name=Sci+Tec&ticketsToWin=1&totalWinners=2';
var encoded = encodeURIComponent(str);
see the docs or this Question
I'm pretty sure that the plus sign in URLs is used instead of a space, like in a google search, you give the following query:
"How to send an email",
It will show in the URL as:
"How+to+send+an+email".
Try POSTing it.
In Urls, spaces in query strings are automatically replaced by plus signs. So when the server gets Sci+Tec, it thinks there is supposed to be a space there. You will need to escape it with its url encoding: %2B.
More on Url encoding: http://www.w3schools.com/tags/ref_urlencode.asp
you could either use a java url encode or a javascript encoder
URLEncoder.encode(yourString)
Following url is working fine:
http://www.domain.com/address
but when I pass any querystring like:
http://www.domain.com/address?back=order-opc.php?step=1
It shows 404 page
my rewrite:
"^/address" => "/address.php",
i have tried so many different rewrite nothing seems to work...
how should i rewrite ?
You should take in count the rest of the query string in your rule.
"^/address(\?.*)?" => "/address.php$1",
Your query string should be:
http://www.domain.com/address/?back=order-opc.php?step=1
Note the slash / as /address means /address/index.php or /address/index.html ( or whatever is your default document )