URL重写web.config
我需要一点帮助来重写url。我的php站点正在windows server上运行。我正在尝试重写URL,使类别和文章看起来如下: hxxp://domain.com/category-nameURL重写web.config,url,mod-rewrite,url-rewriting,Url,Mod Rewrite,Url Rewriting,我需要一点帮助来重写url。我的php站点正在windows server上运行。我正在尝试重写URL,使类别和文章看起来如下: hxxp://domain.com/category-name hxxp://domain.com/article-title 这是我在web.config中看到的。它对分类很有效,但对文章无效,我做错了什么 <rule name="category"> <match url="^([_0-9a-z-]+)" /> &l
hxxp://domain.com/article-title 这是我在web.config中看到的。它对分类很有效,但对文章无效,我做错了什么
<rule name="category">
<match url="^([_0-9a-z-]+)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="category.php?slug={R:1}" />
</rule>
<rule name="article">
<match url="^([_0-9a-z-]+)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="article.php?slug={R:1}" />
</rule>
因为规则是按显示顺序触发的。所以当你想重写这篇文章时,你需要一些东西来避免触发第一条规则 例如,按照您已有的约定,可以是:
<rule name="category">
<match url="^category-([_0-9a-z-]+)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="category.php?slug={R:1}" />
</rule>
<rule name="article">
<match url="^article-([_0-9a-z-]+)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="article.php?slug={R:1}" />
</rule>
第一条规则仅在路径以类别-
开头时触发,第二条规则仅在路径以文章-
开头时触发
请注意,使用{R:1}
作为反向引用,您将只拥有类别-
或文章-
之后的内容,因此如果您希望保持与以前相同的行为,可以使用{R:0}