简体   繁体   中英

How would i make a rewrite location based of IIS Rewrite Rules?

I'd like to convert an IIS rewrite into Nginx rewrite syntax. I am looking for a way to translate a URL that is looking like this: "/pages.php?page=leaderboard" into "/leaderboard". My IIS Rewrite Rule is:

<match url="^([^/]+)/?$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="pages.php?page={R:1}" />

I am looking for a way to translate a URL that is looking like this: "/pages.php?page=leaderboard" into "/leaderboard".

server {
  rewrite ^/pages.php\?page=leaderboard$ /leaderboard permanent;
  ...
}

You can dynamically capture the page URL parameter using RegEx parentheses groups:

server {
  # /pages.php?page=foo&section=bar  =>  /foo?section=bar
  rewrite ^/pages.php\?page=([^&]+) /$1 permanent;
  ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM