0

URLの書き換えについて少し助けが必要です。私のphpサイトはWindowsサーバーで実行されています。カテゴリと記事の両方が次のようになるように、URL を書き直そうとしています。

hxxp://domain.com/
カテゴリ名 hxxp://domain.com/記事タイトル

これは私が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>
4

1 に答える 1

0

ルールは表示された順序でトリガーされるためです。したがって、記事を書き直したいときに最初のルールをトリガーしないようにするための何かが必要です。

たとえば、あなたが持っている規則に従うと、次のようになります。

<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>

最初のルールはパスが で始まる場合にのみトリガーされcategory-、2 番目のルールはパスが で始まる場合にのみトリガーされarticle-ます。

後方参照として使用すると、以前と同じ動作を維持したい場合は、{R:1}その後のものしか得られないことにcategory-注意してください。代わりに使用できます。article-{R:0}

于 2013-05-24T16:32:08.073 に答える