0

目前,我有规则

RewriteRule ^([A-Za-z0-9-/]+)$ myFile.php?myId=$1

我希望能够访问一个文件夹及其文件(让我们说它被称为示例),以及它的 index.php。但是,使用规则

RewriteRule ^example$ example/index.php [L]

相反,它匹配第一条规则。不过,这是文件的第一条规则。

4

2 回答 2

1

执行您的重写规则后,exampleURL 被重写为example/index.php,然后重新进入重写过程(该[L]标志不会阻止)。然后,您的其他重写规则匹配。

所以你必须为example/index.php. 例如:

RewriteRule ^example/index.php$ - [L]

这会终止第二次重写运行。确保将其插入到您的其他规则之上。

于 2012-06-02T12:00:14.473 回答
0

你可以使用一个条件:

RewriteCond %{REQUEST_URI} !^/example
RewriteRule ^([A-Za-z0-9-/]+)$ myFile.php?myId=$1 [L]

这样,您将获得规则匹配,除非请求以“/example”开头。您可以添加额外的斜线,即“/example/”以避免不匹配的“/example-page”。

于 2012-06-02T10:32:42.870 回答