简体   繁体   English

IIS7 URL 重写规则以执行从 *.html 文件到 *.php 文件的 301 重定向

[英]IIS7 URL Rewrite rule to perform a 301 redirect from *.html files to *.php files

I would like to use the URL Rewrite module of IIS7 to create 301 redirects based on a specific pattern.我想使用 IIS7 的 URL 重写模块根据特定模式创建 301 重定向。

I have a web site that consists of only.HTML files.我有一个 web 站点,其中仅包含 .HTML 文件。 I am converting the site to.PHP files, but keeping all of the same filenames.我正在将该站点转换为 .PHP 文件,但保留所有相同的文件名。 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.谢谢。

Here you go:这里是 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.在 IIS 7.5 和 URL 重写模块 v2.0 上测试——工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM