簡體   English   中英

Web.Config IIS重寫規則

[英]Web.Config IIS Rewrite Rules

我有一個站點,它將所有請求重定向到index.php。 但是,我需要對我的web.config進行一些更改。

這是當前在重定向部分中的內容:

<rewrite>
    <rules>
        <rule name="Process" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php" />
        </rule>
    </rules>
</rewrite>

但是,我需要它,以便如果有人去/ news,那么它將去news.php而不是index.php

我將使用什么規則以及將其放置在哪里? 我來自Apache,但是我的客戶使用的是IIS。

您可以在現有規則之上插入其他規則,並進行一些更改以重定向到您的位置。

這也可以在IIS管理器中完成。 通過此操作,您可以測試所用的語法,以查看其是否與所需的網址一起使用。

<rule name="Rewrite-News" patternSyntax="ExactMatch" stopProcessing="true">
    <match url="news" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="news.php" appendQueryString="false" />
</rule>

因此,一切看起來都像這樣:

<rewrite>
    <rules>
        <rule name="Rewrite-News" stopProcessing="true">
            <match url="news" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="news.php" appendQueryString="false" />
        </rule>
        <rule name="Process" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php" />
        </rule>
    </rules>
</rewrite>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM