<?xml version="1.0" encoding="UTF-8"?>
<rules>
<clear />
<rule name="wfq2020">
<match url="^(auth|platform-admin|product|substation-admin)/(.*)" />
<action type="Rewrite" url="https://google.com/{R:0}" />
</rule>
<rule name="api.wfq2020">
<match url="^(wuneng-platform-web|wuneng-channel-web|wuneng-web|wuneng-user-web|mini-program)/(.*)" />
<action type="Rewrite" url="https://api.google.com/{R:0}" />
</rule>
</rules>
Here is my iis rule, I want to convert it to nginx rule, hope someone can help me!
CodePudding user response:
I'm not super familiar with IIS rewrite, but I have checked their doc and it seems pretty close to NGINX.
On NGINX, is recommended to use return
if possible (doc here). The {R:0}
is similar to the NGINX vars, in this case, the $request_uri
.
You can also combine with the ~*
, this is a "Regular expressions are specified with the preceding “~*” modifier (for case-insensitive matching)" (doc here). The ^/...
means that it needs to start with it (e.g. starts with /wuneng-platform-web
and anything else after that (.*)
.
The code will be something like:
http {
## ...
server {
## ...
location ~* ^/(auth|platform-admin|product|substation-admin)(.*) {
return 301 https://google.com$request_uri;
}
location ~* ^/(wuneng-platform-web|wuneng-channel-web|wuneng-web|wuneng-user-web|mini-program)(.*) {
return 301 https://api.google.com$request_uri;
}
## ...
}
## ...
}
I hope this will help you out :)