如果你把这个放在你的 .htaccess 文件中
Options MultiViews
你有这些文件
stuff/
howto.html
index.php
items.php
那么所有这些网址都可以
/stuff/ # brings up /stuff/index.php.
# Yes, this would have worked
`# even without MultiViews
/stuff/howto # brings up /stuff/howto.html.
#`This would not have
# worked without MultiViews,
# although you could have done
# it with a Rewrite rule, too
/stuff/items # brings up /stuff/items.php
/stuff/items/1234 # brings up /stuff/items.php,
# and sets $_SERVER['PATH_INFO']
# to '/1234'
/stuff/items/2010/03/01/how-to-plant-a-garden
# brings up /stuff/items.php, and
# sets $_SERVER['PATH_INFO']
# to '/2010/03/01/how-to-plant-a-garden'.
# If my file layout was different,
# like /stuff/items/2010.php,
# then it would have brought up
# 2010.php, and given it the PATH_INFO
# string of '/03/01/how-to-plant-a-garden'
# So it seems Apache searches the string
# from right to left for a file
放入MultiViews
.htaccess 文件比使用重写规则要短得多。
但现在我正在研究 nginx,还没有找到等效的。它不必这么短。我知道try_files可以处理没有 PATH_INFO 字符串的文件。但是对于带有 PATH_INFO 的文件,我发现的唯一方法是为每个 PHP 文件设置重写规则,尤其是那些在 PATH_INFO 中使用斜杠的文件。