我希望它能够使所有没有".php"扩展名的URL请求都由适当的.php文件处理,并且仍然能够使用".php"扩展名命名这些文件。
<DirectoryMatch "/var/www/html"> #This works for the one directory
RewriteEngine on
RewriteRule "^(w+)$" "$1.php"
</DirectoryMatch>
这应该适用于所有子目录:
<DirectoryMatch "^(/var/www/htm).*"> #This does not work
以下是我尝试过的事情列表,我认为它们应该都是一样的,但事实并非如此:
<DirectoryMatch "/var/www/html"> #this works
<DirectoryMatch /var/www/html> #this works
<DirectoryMatch "^/var/www/html"> #"The requested URL was not found on this server."
<DirectoryMatch "^/var/www/html$"> #"The requested URL was not found on this server."
<DirectoryMatch "^(/var/www/html)$"> #"The requested URL was not found on this server."
<DirectoryMatch "^(/var/www/htm).*"> #"The requested URL was not found on this server."
似乎一旦我实际使用正则表达式,它就不再有效。 但是,重写规则中的正则表达式确实有效。
为什么正则表达式不适用于 DirectoryMatch?
我能做的最好的事情就是为每个目录写一个单独的条目:
<Directory "/var/www/html/test">
RewriteEngine on
RewriteRule "^(w+)$" "$1.php"
</Directory>
<Directory "/var/www/html/dashboard">
RewriteEngine on
RewriteRule "^(w+)$" "$1.php"
</Directory>
<Directory "/var/www/html/dashboard/wizard">
RewriteEngine on
RewriteRule "^(w+)$" "$1.php"
</Directory>