Nginx rewrite by map with parameters - nginx

I would like to rewrite with map as
/oldpage?f=regist -> /signup
/oldpage?f=regist&a=1 -> /signup?a=1
/oldpage?f=confirm -> /signup?t=confirm
/oldpage?f=confirm&a=1 -> /signup?t=confirm&a=1
but my redirect result in nginx (v1.12.2) is
/oldpage?f=regist -> /signup?f=regist
/oldpage?f=regist&a=1 -> Not Found
/oldpage?f=confirm -> /signup?t=confirm?f=confirm
/oldpage?f=confirm&a=1 -> Not Found
I set nginx.conf as,
map $request_uri $rewrite_uri {
include conf.d/redirect.map;
}
server {
...
if ($rewrite_uri) {
rewrite ^ $rewrite_uri redirect;
}
}
and redirect.map is
/oldpage?f=regist /signup;
/oldpage?f=confirm /signup?t=confirm;
It would be really appreciated if you could give me some advices.

If the a=1 parameter represents any other parameters, and you do not wish to add those combinations to the map file, you should change the syntax of your map file to use regular expressions.
The regular expressions in the map block can create named captures which can be used later in the configuration. In the example below, the $prefix and $suffix variables are named captures from the map block.
The example below has some caveats - because the $prefix and $suffix values may be empty, the generated URIs may contain a trailing ? or & - which should not affect the overall semantics.
All of the regular expressions and the mapped values have a common pattern to capture optional parameters and append them to the resulting value.
map $request_uri $new {
default 0;
~*^/oldpage\?(?<prefix>.*&)?f=regist(&(?<suffix>.*))?$ /signup?;
~*^/oldpage\?(?<prefix>.*&)?f=confirm(&(?<suffix>.*))?$ /signup?t=confirm&;
}
server {
...
if ($new) {
return 301 $new$prefix$suffix;
}
See this document for more.

Related

Firebase Cloud Storage security rules: what do "/b/" and "/o" mean in bucket match statement?

This question is regarding Firebase Cloud Storage security rules, documented at https://firebase.google.com/docs/storage/security and related pages.
The statement to match a generic bucket is match /b/{bucket}/o: the documents explain that {bucket} is a wildcard (akin to *) to match any bucket name, but to me it seems that the meaning of the leading /b/ and trailing /o are left unexplained, can anyone help me understand the meaning of those path segments?
The /b signals the next component of the URI is the relevant bucket: /b/{bucket}.
The /o signals the next component of the URI is the name (or path) of the relevant object in that bucket: /o/path/to/object.png
Note: Storage Buckets don't have a concept of folders, an object's name can include slashes, but to the server, the slash is just part of the file name and has no special meaning.
So a rule that names /b/{bucket}/o/publicUserFiles/{request.auth.uid}/profile.png would define a rule for the profile.png file, stored in a "folder" named with the relevant user's UID, under another "folder" called publicUserFiles, in the relevant bucket.
Instead of putting /b/{bucket}/o at the front of every rule, you can lift it out to the top of the file.
i.e.
service firebase.storage {
match /b/{bucket}/o/images/{imageId} {
allow write: // some rule here;
}
match /b/{bucket}/o/profileImages/{imageId} {
allow write: // some rule here;
}
}
becomes
service firebase.storage {
match /b/{bucket}/o {
match /images/{imageId} {
allow write: // some rule here;
}
match /profileImages/{imageId} {
allow write: // some rule here;
}
}
}

Need help for mapping dynamic data with nginx

i have a content like this ( can be stored in a text file or database or etc):
[
{
"site_slug": "/site1",
"site_url": "http://site1.com"
}
]
i want nginx can read the data and map the location path with key: "site_slug" and redirect to "site_url"
is it possible? could you give me some keywords for googling?

How to filter non-resolvable URIs on a SPARQL query?

Is it possibe to filter out results that contains a non-resolvable URI within the SPARQL query?
An example: I'm making the following query (endpoint: http://linkeddata.systems:8890/sparql):
PREFIX RO: <http://www.obofoundry.org/ro/ro.owl#>
PREFIX SIO: <http://semanticscience.org/resource/>
PREFIX EDAM: <http://edamontology.org/>
PREFIX PHIO: <http://linkeddata.systems/ontologies/SemanticPHIBase#>
PREFIX PUBMED: <http://linkedlifedata.com/resource/pubmed/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX up: <http://purl.uniprot.org/core/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT DISTINCT ?disn_1 ?label ?rel ?valor
WHERE { ?disn_1 ?rel ?valor . ?disn_1 rdfs:label ?label FILTER(( ?disn_1 = <http://linkeddata.systems/SemanticPHIBase/Resource/host/HOST_00561>))}
In the results, as you can see there is in ?valor variable a triple that contains a non-resolvable URI (text: /hostncbitaxid/). I would like to know if there is some specific FILTER that can be added in the SPARQL query to remove those results with non-resolvable URIs.
I'm having problems with the API that I'm using to process these results in C# because it is returning an exception due to non-resolvable URIs so I would like to filter them out in the SPARQL query (if possible).
How do you know that it's not resolvable? RDF doesn't have a concept of a "relative URI", all the URIs are resolved relative to something (and perhaps to what is an implementation detail in some cases), so you end up with absolute URIs. In the HTML results from that endpoint, I get http://linkeddata.systems:8890/hostncbitaxid/, and that could easily be resolvable.
That said, if you are ending up with results that include non-absolute URIs, and you want to filter those out, you could use some heuristics to do that. For instance, if you only want URIs beginning with http, you can do that. E.g., here's a query that returns two values for ?uri:
prefix : <urn:ex:>
select * where {
values ?uri { <http://www.example.org/> </foobar> }
}
-----------------------------
| uri |
=============================
| <http://www.example.org/> |
| <file:///foobar> |
-----------------------------
(Notice that the relative URI /foobar got resolved as a file:// URI.) You can keep only http URIs with a filter:
prefix : <urn:ex:>
select * where {
values ?uri { <http://www.example.org/> </foobar> }
filter strstarts(str(?uri), "http")
}
-----------------------------
| uri |
=============================
| <http://www.example.org/> |
-----------------------------
The query returns (SPARQL results in JSON format):
"valor": { "type": "uri", "value": "/hostncbitaxid/" }}
This is bad data - it must be an absolute URI in RDF. Presumably the data is bad. You can remove it in the query as #joshua-taylor shows.

Meteor: Iron.Router Catch All (Will match the rest of the URI)

Is it possible to define a Iron.Router route with a parameter that will match the rest of the URI?
For example
Router.route('results', {
path: '/test/:domain'
});
This will match on entries like
/test/hello
/test/hello.com
What I really need, is to also match on entries such as
/test/hello.com/about
/test/hello.com/about?param=3
Thoughts?
Figured out how!
In this case the path will now be
Router.route('results', {
path: '/test/(.*)'
});
To access the trailing info, access the parameter at index 0
this.params[0]

Variable interpolation inside Map directive

I am trying to map a variable inside the http directive in Nginx.
When left alone, the variable alone gets expanded, if I add anything else to the string the expansion stops working.
http {
map $host $foo {
#default "$host"; # - this works fine and returns 'localhost'
default "This is my host: $host"; # - THIS DOESN'T WORK
}
server {
location / {
echo $foo;
}
}
}
Do you have any suggestions to make the expansion work inside the map?
As stated in the map directive documentation :
The resulting value can be a string or another variable (0.9.0).
Update: This functionality has been added to version 1.11.2 of NGinx, as per Comment #7 here: https://trac.nginx.org/nginx/ticket/663#comment:7

Resources