Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
URL重写web.config_Url_Mod Rewrite_Url Rewriting - Fatal编程技术网

URL重写web.config

URL重写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

我需要一点帮助来重写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-]+)" />
        <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}