我想让所有没有".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>