将.htaccess(PHP)行转换为web.config行(IIS)

时间:2014-10-20 02:16:18

标签: .htaccess web-config rewrite iis-7.5

我在.htaccess文件中有这些行,并将我的站点移动到IIS环境。我很确定它需要进入root中的web.config文件,但我完全迷失了,并尝试了一切没有运气。这样做是将.php,.htm或.html的任何内容指向根目录中的index.php页面,这样我就可以控制显示的内容并使模块化。它将在查询字符串中添加文件名,以便我可以从那里引导内容。不管怎样,还有我所拥有的.htaccess:

RewriteCond %{REQUEST_FILENAME} (\.php|.htm|.html)$
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

2 个答案:

答案 0 :(得分:1)

您可以使用此Microsoft支持的URL Rewrite IIS Manager module

导入mod_rewrite rules并将其转换为IIS URL rewrite rules

<强> web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rule 1" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" pattern="\.(php|htm|html)$" ignoreCase="false" />
                    </conditions>
                    <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

答案 1 :(得分:0)

我非常感谢您将我指向url rewrite模块的方向。我已经尝试过使用它,但不知道它有导入功能!!在我导入了.htaccess行后,它仍然无法正常工作(正如预期的那样导入lol),但在我稍微调整了reqex后,一切正常!再次感谢您帮助我。对于那些想要正确的web.config设置的人来说,这是:)

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="Pattern" pattern="(.*php|.*htm|.*html)$" ignoreCase="true" negate="false" />
                    </conditions>
                    <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
相关问题