PHP htaccess文件夹管理


php htaccess folders management

目前我所有的域名请求都通过/index.php

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]

然而,我想添加一个例外。如果请求转到文件夹"/this_specific_folder/",那么它应该转到"/this_specific_folder/index.php"而不是"/index.php",而不会破坏当前存在的逻辑。

我怎样才能做到这一点?

你可以这样做:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(this_specific_folder)(?:/.*)?$ /$1/index.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]    
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]