Comments (9)
Hi,
Take a look at this #732 (comment).
You might write the configuration like:
-- deleted --
{
"match": {
"uri": "~^(?<some_var>.*)$"
},
"action": {
"set": {
"args": "/index.php?__path__=/$some_var"
}
}
}
Unit now doesn't support custom variables from regexp with the rewrite
option.
We will support it in the 1.33 version. On the 1.32 currently.
from unit.
You might write the configuration like:
{ "match": { "uri": "~^(?<some_var>.*)$" }, "action": { "rewrite": "/index.php?__path__=/$some_var" } }
The previous request arguments are appended after a ?
. In this case, there will be two ?
in the rewritten URI.
Lines 91 to 93 in 822303e
Nginx handles this by appending a &
instead of ?
in ngx_http_script.c.
from unit.
Sorry, I used the wrong configuration.
https://unit.nginx.org/configuration/#uri-rewrite
It does not affect the query but changes the uri and $request_uri variables.
And we have an idea of how to change the query, but it's not clear yet.
It's a topic of updating variables, like:
{
"match": {
"uri": "~^(?<some_var>.*)$"
},
"action": {
"set": {
"args": "/index.php?__path__=/$some_var"
}
}
}
Anyway, we need to support custom variables with the captured regexp names.
Welcome to your suggestions on it.
from unit.
The syntax looks OK, except that I don't think ~
is needed (unless it's part of syntax to enable regex).
You will need to consider what to do with the previous request arguments (i.e. existing arguments before the rewrite). Nginx has a "putting a question mark at the end of a replacement string" way of configuring it, but it's a bit too obscure.
from unit.
Actually, in nginx, you also can set $args
variables to change the request query.
You will need to consider what to do with the previous request arguments
We intend to make the usage as concise as possible, and nginx's way is more powerful with more rules.
As you showed in the source code, the rewrite in nginx is very powerful with more code lines.
from unit.
@hongzhidao as we have worked on #916 we made use of njs
in the rewrite part with some great success in terms of regexs. For example
{
"action": {
"rewrite": "`${uri.replace(/^(\\/[^\\/]+)?(\\/.*\\.php)/, '$2')}`",
"share": "/sites/$host$uri",
"fallback": {
"pass": "applications/$host/index"
}
}
}
In this example we are using matching blocks of the regext to build a new URI. Coulnd't this help in this case?
from unit.
It looks like the case is related to how to change/rewrite the request query/arguments. And the rewrite
option only affects the uri.
from unit.
Okay then scratch that. Let's think about enhancing the rewrite support and what release is a good fit for that.
from unit.
https://nginx.org/en/docs/http/ngx_http_rewrite_module.html
If a replacement string includes the new request arguments, the previous request arguments are appended after them. If this is undesired, putting a question mark at the end of a replacement string avoids having them appended, for example:
I would say the rule is complicated, It has advantages and disadvantages in terms of use and implementation cost.
from unit.
Related Issues (20)
- Missing http.ServerResponse.flushHeaders function HOT 4
- Unit building PHP modules. Version confusion. HOT 7
- Unable to compile an nginx unit Golang application under Windows HOT 1
- Docker: Unable to build images for PHP 8.3.0RC6 using packages Makefile HOT 17
- PHP 8.3 official unit image HOT 7
- Add HTTP Range header support HOT 1
- Can Unit run NodeJS Nuxt applications? HOT 8
- Nginx unit daemon json logs HOT 3
- Best practice for handling concurrent jobs in a multi-instance Express app HOT 1
- python asgi stop response HOT 6
- Are Python WebSockets under SSL intended to work? HOT 10
- Support for request headers HOT 2
- Does ngix for windows support http_perl_module? HOT 2
- npm: unit-http: should we replace the https package as well?
- Nginx unit's analog for fpm max_children HOT 1
- how to add in image HOT 3
- compile unit with only needed language support
- Trailing slash rewrite - duplicated content SEO issue
- "error": "Failed to apply new configuration." - REG HOT 2
- questions around embedding `libunit` in Julia HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unit.