0

我有这个 RewriteRule :

RewriteRule !^(div|sitemapXML|cache|AJAX|xml|html|favicon.ico|robots.txt|script|cms|style|image|inc|img|templates|index.html) index.php

但例如“ http://www.mydomain.com/divindu/ ”会因为排除“div”而被忽略。在这里处理文件夹的最佳方法是什么?我应该在名字后面加上斜杠吗?

4

2 回答 2

2

看起来您正在尝试实现忽略现有文件的包罗万象的规则。您应该为此简单地使用 Apache 的 FallbackResource 指令。对于旧版本的 Apache,或更精细的控制,查看 RewriteCond 的特殊 -d 和 -f 标志,您可以使用它们从 RewriteRule 显式排除现有文件和文件夹。

于 2013-04-12T19:07:14.270 回答
2

根据类型、常规文件或目录,您可以附加斜杠/或字符串结尾的美元符号$。您还可以将模式移动到 aRewriteCond并将目录和文件拆分为两个

# exclude some directories
RewriteCond %{REQUEST_URI} !^/(div|sitemapXML|cache|AJAX|xml|html|script|cms|style|image|inc|img|templates)/
# exclude some existing files
RewriteCond %{REQUEST_URI} !^/(favicon.ico|robots.txt|index.html)$
RewriteRule ^ index.php [L]

或者,如果您想像@Niels 假设的那样排除所有现有文件和目录,您可以使用

# exclude existing files
RewriteCond %{REQUEST_FILENAME} !-f
# exclude directories
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
于 2013-04-12T20:42:10.220 回答