htaccess:通配符文件夹和url



我有一些域,例如http://domain.com

http://domain.com/sport -> Folder actually exits
http://domain.com/sport/123/ - > Folder dont exist
http://domain.com/sport/123/hello.html - > file dont exist

所以当http://domain.com/sport/123/或访问http://domain.com/sport/123/hello.html。。它必须显示第一个文件夹index.php的内容,而不是抛出未找到的错误,也就是说,在本例中,它必须显示http://domain.com/sport/index.php 的内容

我尝试了以下代码。但它抛出了500个内部错误

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/.*$ /$1/index.php [L]

如果将所有重写规则封装在IfModule容器中,是否仍然会出现500内部服务器错误?例如

<IfModule mod_rewrite.c>
   # Turn mod_rewrite on
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^([^/]+)/.*$ /$1/index.php [L]
</IfModule>

如果您停止获取错误,但重写仍然不起作用,则意味着您必须打开重写模块。如何做到这一点完全取决于您的设置、托管服务设置和/或您是否有权访问httpd.conf文件。

最新更新