转换web.config URL将规则重写为.htaccess

时间:2013-08-24 14:59:21

标签: .htaccess iis mod-rewrite url-rewriting web-config

我在web.config中有以下IIS网址重写规则:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="some-name" patternSyntax="Wildcard">
                    <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>
    </system.webServer>
</configuration>

它们适用于任何子文件夹,如下所示:

案例A

web.config和index.php存储在folder1/test中:
请求/folder1/test/some/virtual/12-url已发送至folder1/test/index.php

<案例B

web.config和index.php存储在folder2/wherever/this中:
请求/folder2/wherever/this/virtual/12-url已发送至folder2/wherever/this/index.php

为了切换到Apache,如何重写这些规则 每当子文件夹URL更改时,都无需更新.htaccess? (项目可以托管在任何子文件夹上,不需要放在文档根目录中。)

1 个答案:

答案 0 :(得分:1)

试试这个

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^ index.php [L]