0

我有以下 IIS URL 重写规则web.config

<?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?(该项目可以托管在任何子文件夹中,不需要放在 Document Root 中。)

4

1 回答 1

1

尝试这个

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^ index.php [L]
于 2013-08-24T21:08:25.197 回答