URL Rewrite troubleshoot

2019-07-24 02:55发布

问题:

We have our URL rewrite as followed. I tested the pattern in IIS 8.5 URL Rewrite and the patterns matched as what we wanted. However, it's 404 every single time. Will someone take a look and see what is wrong with my URL rewrite? Thank you.

URL: devbox.mysite.com/article/how-to-use-onedrive

Pattern: (.*)/article/(.*)$
Action Rewrite URL: {R:1}/article/?artID={R:2}

Currently the page shows 404. Below is the XML code in web.config file.

<rule name="Article-rewrite" enabled="true">
    <match url="(.*)/article/(.*)$" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="Rewrite" url="{R:1}/article/?artID={R:2}" appendQueryString="false" />
</rule>

回答1:

Try this:

<rule name="Article-rewrite" enabled="true"> 
    <match url="article/(.*)$" /> 
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" /> 
    <action type="Rewrite" url="article/?artID={R:1}" appendQueryString="false" /> 
</rule>

I've removed the domain from the match url, as you're not switching the domain.