我想要这样,所有不带“ .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"> #Does NOT work, is this not the same thing?
<DirectoryMatch "^/var/www/html$"> #Does NOT work, is this not the same thing?
<DirectoryMatch "^(/var/www/html)$"> #Does NOT work, is this not the same thing?
似乎我实际使用正则表达式后,它就不再起作用。但是,重写规则中的正则表达式确实有效。
任何人都可以重现此行为吗?
我能做的最好的就是为每个目录写一个单独的条目:
<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>