简体   繁体   中英

IIS URL rewrite with optional parameters for page no

I need a help writing rewrite rule for the following url pattern

www.mydomain.com/list-of-(buyers|suppers|all)-in-(location-name)/page/10.html
  1. The first parameter will be 'buyers' or 'suppliers' or 'all'
  2. The second parameter can be ANY location name
  3. '/page/number' part is optional
  4. url will always end with '.html'

UPDATE:

I have managed to write a rewrite rule which successfully matches the following url:

mysite.com/list-of-buyers-in-goa/page/5.html .

The same rule is not working for the below url

mysite.com/list-of-buyers-in-goa.html

ie when I remove the page/no part from the url, it doesn't work. I don't need page/no parameter for the first page.

Since all the other pages on website are .html pages, just to maintain the uniformity, I want the url to always end with .html

Here is my rewrite rule

    <rule name="Rewrite rule for listing members">
      <match url="^list-of-([a-z-A-z]+)-in-([a-zA-z-]+)?(\/page\/)?([\d+])?\.html$" />
      <action type="Rewrite" url="members.aspx?type={R:1}&amp;location={R:2}&amp;page={R:4}" />
    </rule>

--

Try like this;

.*.com\/list-of-(buyers|suppers|all)-in-.*html$

I tested it with "mysite.com/list-of-buyers-in-goa.html" and mysite.com/list-of-buyers-in-goa/page/1234.html , it matched.

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