IIS7 URL Rewrite rule to perform a 301 redirect fr

2020-03-25 06:25发布

问题:

I would like to use the URL Rewrite module of IIS7 to create 301 redirects based on a specific pattern.

I have a web site that consists of only .HTML files. I am converting the site to .PHP files, but keeping all of the same filenames. For example, the following urls...

/index.html
/contact/contact.html
/membership/member.html

will become...

/index.php
/contact/contact.php
/membership/member.php

Can anyone advise on how to create this rule?

Thanks.

回答1:

Here you go:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="html2php" stopProcessing="true">
                <match url="^(.+)\.html$" />
                <action type="Redirect" url="{R:1}.php" redirectType="Permanent" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

Tested on IIS 7.5 with URL Rewrite module v2.0 -- works fine.