Disclaimer: None of the following are tested. Please use it with caution. If anything goes wrong, please turn on debugging as mentioned at http://nginx.org/en/docs/debugging_log.html .
See if it's a real file or directory, if so, serve it,
then send all requests for / to Director.php
This may be achieved with...
server {
index Directory.php;
location / {
try_files $uri $uri/ /Directory.php;
}
}
The index
directive is enough for directory index. To send all requests to Director.php, then location block is needed.
If the URL has one segment, pass it as rt
You may try the following...
rewrite "^/([a-zA-Z0-9\-\_]+)/$" "/Director.php?rt=$1" last;
Please remember the quotes around the rewrites. It is preferable to use quotes, and is needed on certain conditions (that is mentioned in the link provided earlier by @jerm).
If the URL has two segments, pass it as rt and action
You may try the following...
rewrite "^/([a-zA-Z0-9\-\_]+)/([a-zA-Z0-9\-\_]+)/$" "/Director.php?rt=$1&action=$2" last;
Please note that I haven't done anything for QSA in the above examples. You may try $args
variable in Nginx to pass the existing query string to the new query string. Ref: http://nginx.org/en/docs/http/ngx_http_core_module.html#variables
I hope that helps to arrive at the full working solution!
First, you shouldn't use root
directive inside the location block, it is a bad practice. In this case it doesn't matter though.
Try adding a second location block:
location ~ /some/path/(?<section>.+)/index.html {
proxy_pass http://192.168.1.24/$section/index.html;
proxy_set_header Host $host;
}
This captures the part after /some/path/ and before index.html to a $section variable, which is then used to set the proxy_pass destination. You can make the regex more specific if you require.
Best Answer
Your
map
statement is performing a string match on$request_uri
. The variable$request_uri
also includes the query string. If you want to match with and without the query string, you should match only the front of$request_uri
, which can be accomplished using regular expression syntax:See this document for details.