Regex .htaccess是否为具有可变目录数的url加载索引文件?

Regex .htaccess是否为具有可变目录数的url加载索引文件?,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,假设我的根目录中有目录区域: root/regions 如果用户访问以下任一项,我想加载位于regions文件夹中的index.php文件: http://www.example.com/regions/united-kingdom http://www.example.com/regions/united-kingdom/london http://www.example.com/regions/united-kingdom/londom/rm8-16de 国家、城市和邮政编码不作为目录存

假设我的根目录中有目录区域:

root/regions
如果用户访问以下任一项,我想加载位于regions文件夹中的index.php文件:

http://www.example.com/regions/united-kingdom
http://www.example.com/regions/united-kingdom/london
http://www.example.com/regions/united-kingdom/londom/rm8-16de
国家、城市和邮政编码不作为目录存在! 怎么做?
提前谢谢你

顺序应为DirectoryIndex.html index.php//默认为index.html

如果Web服务器在当前目录中未找到与DirectoryIndex指令中的名称匹配的文件,则浏览器将显示目录列表,其中显示当前目录中的所有文件。Apache将按顺序查找上述每个文件,并在访问者只请求一个目录时提供它找到的第一个文件

一旦检查哪种解决方案适合您

如果您对此有任何疑问/担忧,请告知我


谢谢

在您的
区域/.htaccess
中,您可以拥有以下功能。htaccess:

DirectoryIndex index.php
RewriteEngine On
RewriteBase /regions/

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

嗨,谢谢你帮我。我认为你的方法是错误的。DirectoryIndex.html index.php只有在我访问时才会有帮助,但对于其他/countries/city/postcode,它将无法提供帮助,因为它们不作为文件夹存在,如果我尝试访问,我将收到错误500。。目录索引不是解决方案!这就是我所说的大师!:)谢谢你,阿努巴瓦!和往常一样好:)阿努巴瓦,你能看看这个问题吗: